0
A
回答
1
正如@Daniel说,你可以创建一个使用.thumbnail()
缩略图,创建与原始图像的尺寸相同的新图像,然后缩略图粘贴到新的形象:
def scale_image(img, factor, bgcolor):
# create new image with same mode and size as the original image
out = PIL.Image.new(img.mode, img.size, bgcolor)
# determine the thumbnail size
tw = int(img.width * factor)
th = int(img.height * factor)
# determine the position
x = (img.width - tw) // 2
y = (img.height - th) // 2
# create the thumbnail image and paste into new image
img.thumbnail((tw,th))
out.paste(img, (x,y))
return out
factor
应该在0和1之间,并且bgcolor
是新图像的背景颜色。
例子:
img = PIL.Image.open('image.jpg')
new_img = scale_image(img, 0.5, 'white')
new_img.show()
相关问题
- 1. 获取缩放图像的尺寸
- 2. 的Android图像按钮缩放/尺寸
- 3. 保持像素比例,但缩放尺寸
- 4. 枕头使图像比以前更大尺寸
- 5. 将图像缩放到不同的图像视图尺寸
- 6. 缩放图像,但保持其比例
- 7. 缩小图像尺寸imagemagic
- 8. 缩小图像尺寸C#
- 9. 如何缩放图像为一致的图像尺寸
- 10. 机器人图像查看尺寸不与图像缩放
- 11. 画布缩放保留像素尺寸
- 12. 设置UIButton的框架,但保持图像相同的尺寸
- 13. 保存为SD之前缩放摄像头图片尺寸的最佳方法
- 14. 使用箱尺寸:“边界框”,并保持图像尺寸
- 15. 的Android,摄像头和“实际”支持的图像尺寸
- 16. ModalPopupExtender缩略图和全尺寸图像
- 17. 图像尺寸,
- 18. 图像尺寸
- 19. Python枕头自动图像编辑
- 20. Python枕头Tkinter,破坏图像,
- 21. 减少图像尺寸,但保持最高质量/分辨率?
- 22. 如何将容器尺寸拉伸至按比例缩放的儿童尺寸
- 23. 儿童div来放置在父div的顶部图像
- 24. 压缩的EPS illustartor图像尺寸
- 25. 图像的尺寸缩减方法
- 26. fabricjs中缩小尺寸的图像pixelated
- 27. 如何将位图压缩为较小尺寸的图像(保持纵横比)
- 28. ImageView位图缩放尺寸
- 29. 使用Silverlight进行图像缩放(缩小尺寸)
- 30. 减少像素和尺寸以保持完整图像
你怎么样倾倒缩略图成一个更大的缓冲?不知道如何与枕头做 – Netwave