使用 python 为 jpeg 创建缩略图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2612436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-04 01:04:24 来源:igfitidea点击:
Create thumbnail images for jpegs with python
提问by RC1140
As the title says i am looking for a way convert a huge number of images into thumbnails of different sizes , How do i go about doing this in python
正如标题所说,我正在寻找一种方法将大量图像转换为不同大小的缩略图,我如何在 python 中执行此操作
回答by Kevin Sylvestre
See: http://www.pythonware.com/products/pil/index.htm
请参阅:http: //www.pythonware.com/products/pil/index.htm
import os, sys
import Image
size = 128, 128
for infile in sys.argv[1:]:
outfile = os.path.splitext(infile)[0] + ".thumbnail"
if infile != outfile:
try:
im = Image.open(infile)
im.thumbnail(size)
im.save(outfile, "JPEG")
except IOError:
print "cannot create thumbnail for", infile