在Python中生成图像缩略图的最快方法是什么? [英] What is the fastest way to generate image thumbnails in Python?

查看:533
本文介绍了在Python中生成图像缩略图的最快方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Python构建一个照片库,希望能够快速生成高分辨率图像的缩略图。

I'm building a photo gallery in Python and want to be able to quickly generate thumbnails for the high resolution images.

生成高质量图像的最快方法是什么各种图像源的缩略图?

What's the fastest way to generate high quality thumbnails for a variety of image sources?

我应该使用像imagemagick这样的外部库,还是有一种有效的内部方法来做到这一点?

Should I be using an external library like imagemagick, or is there an efficient internal way to do this?

已调整大小的图片的尺寸为(最大尺寸):

The dimensions of the resized images will be (max size):

120x120
720x720
1600x1600

质量是一个问题,因为我想保留尽可能多的原始颜色尽可能最小化压缩工件。

Quality is an issue, as I want to preserve as many of the original colors as possible and minimize compression artifacts.

谢谢。

推荐答案

你想要PIL它可以轻松地完成这个任务

You want PIL it does this with ease

from PIL import Image
sizes = [(120,120), (720,720), (1600,1600)]
files = ['a.jpg','b.jpg','c.jpg']

for image in files:
    for size in sizes:
      Image.open(image).thumbnail(size).save("thumbnail_%s_%s" % (image, "_".join(size)))

如果你迫切需要速度。然后编程,多处理或获取另一种语言。

If you desperately need speed. Then thread it, multiprocess it or get another language.

这篇关于在Python中生成图像缩略图的最快方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆