您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在Python中使用PIL将图像合成到另一个图像?

如何在Python中使用PIL将图像合成到另一个图像?

这可以通过Image实例的paste方法来完成:

from PIL import Image
img = Image.open('/path/to/file', 'r')
img_w, img_h = img.size
background = Image.new('RGBA', (1440, 900), (255, 255, 255, 255))
bg_w, bg_h = background.size
offset = ((bg_w - img_w) // 2, (bg_h - img_h) // 2)
background.paste(img, offset)
background.save('out.png')

可以在Nadia Alramli的PIL教程中了解方法以及其他许多PIL技巧

python 2022/1/1 18:46:44 有339人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶