码迷,mamicode.com
首页 > 编程语言 > 详细

python裁剪图片

时间:2020-07-19 16:13:22      阅读:67      评论:0      收藏:0      [点我收藏+]

标签:from   print   pen   port   style   color   pre   bsp   span   

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裁剪图片

标签:from   print   pen   port   style   color   pre   bsp   span   

原文地址:https://www.cnblogs.com/xdd1997/p/13339148.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!