首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用PIL调整图像大小并保持其纵横比?

如何使用PIL调整图像大小并保持其纵横比?
EN

Stack Overflow用户
提问于 2008-11-08 07:08:04
回答 23查看 889K关注 0票数 546

有没有什么明显的方法可以解决我没有注意到的问题呢?我只是想做些缩略图。

EN

Stack Overflow用户

发布于 2021-11-16 13:04:27

代码语言:javascript
运行
复制
# Importing Image class from PIL module
from PIL import Image

# Opens a image in RGB mode
im = Image.open(r"C:\Users\System-Pc\Desktop\ybear.jpg")

# Size of the image in pixels (size of original image)
# (This is not mandatory)
width, height = im.size

# Setting the points for cropped image
left = 4
top = height / 5
right = 154
bottom = 3 * height / 5

# Cropped image of above dimension
# (It will not change original image)
im1 = im.crop((left, top, right, bottom))
newsize = (300, 300)
im1 = im1.resize(newsize)
# Shows the image in image viewer
im1.show()
票数 2
EN
查看全部 23 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/273946

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档