python裁剪图片
Posted xdd1997
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python裁剪图片相关的知识,希望对你有一定的参考价值。
from PIL import Image img = Image.open(‘F:desktop爬取的图片pic.jpg‘) (picW,picH) = img.size # 欲裁剪为4*3 bili = 4/3 if picW/picH>=bili: print(‘weight pic‘) picW2 = picH*bili left = (picW-picW2)/2 right = left + picH*bili upper = 0 lower = picH cropped = img.crop((left, upper, right, lower)) # (left, upper, right, lower) #print(left, upper, right, lower) else: print(‘height pic‘) picH2 = picW /bili left = 0 upper = (picH - picH2) / 2 right = picW lower = upper + picW / bili cropped = img.crop((left, upper, right, lower)) # (left, upper, right, lower) cropped.save("F:desktop爬取的图片pic.jpg")
以上是关于python裁剪图片的主要内容,如果未能解决你的问题,请参考以下文章