使用Python为 JPEG 创建缩略图
正如标题所说,我想找到一种方法,把大量的图片转换成不同大小的缩略图,我该如何在Python中实现这个呢?
1 个回答
22
查看这个链接: 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