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

标签 python image-processing

正如标题所说,我正在寻找一种将大量图像转换为不同大小的缩略图的方法,我如何在 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/

相关文章:

Python——函数不返回值

python - 返回所有单词的正则表达式,星号之间的任何文本除外

python - 获取 Pandas Dataframe 列作为 2D numpy 数组 dtype

opencv - 将L形分成两行

python - 生成小于 10KB 且不丢失比例的图像缩略图

image - 如何检测只有红色物体的图像中的边缘

python - 在 Fedora 24 上的 Python3 中使用 `cairo.Region` 时出现段错误

c++ - MFC:从 CImage 保存到数据库作为选定的文件类型

opencv - 从Houghline获取至少一行

Python删除所有文件夹但不删除文件