gpt4 book ai didi

python - 使用 python 创建 jpeg 的缩略图

转载 作者:太空狗 更新时间:2023-10-30 00:24:41 26 4
gpt4 key购买 nike

正如标题所说,我正在寻找一种将大量图像转换为不同大小的缩略图的方法,我如何在 python 中执行此操作

最佳答案

参见: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

关于python - 使用 python 创建 jpeg 的缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2612436/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com