非常快速(主要是)无损jpeg转换
jpegtran-cffi的Python项目详细描述
jpegtran cffi是一个用于快速jpeg转换的python包。与 其他更通用的图像处理库,如wand-py或 PIL/Pillow,转换的速度通常是 Benchmarks)。此外,除了缩放以外的所有操作都是无损的, 因为在此过程中图像没有被重新压缩。这是因为 所有转换操作都直接处理jpeg数据。
这是通过使用启蒙计划中的多个C例程来实现的 epeg library(用于缩放)和jpegtran来自独立jpeg组的 libjpeg库(用于所有其他操作)。这些例程是从 python通过CFFI模块,即不启动外部进程。
该包还包括获取和设置exif的基本支持。 方向标签,根据它自动转换图像 获取jfif缩略图。
jpegtran cffi是作为spreads 项目中,必须准备大量来自数码相机的图像 由树莓皮展示。使用pi相当慢的armv6处理器,两者 魔杖和皮尔太慢,无法使用。
要求
- cpython 2.6、2.7、3.3或pypy
- CFFI
- 带标题的libjpeg8(早期版本不起作用)
安装
$ pip install jpegtran-cffi
用法
from jpegtran import JPEGImage img = JPEGImage('image.jpg') # JPEGImage can also be initialized from a bytestring blob = requests.get("http://example.com/image.jpg").content from_blob = JPEGImage(blob=blob) # Reading various image parameters print img.width, img.height # "640 480" print img.exif_orientation # "1" (= "normal") # If present, the JFIF thumbnail can be obtained as a bytestring thumb = img.exif_thumbnail # Transforming the image img.scale(320, 240).save('scaled.jpg') img.rotate(90).save('rotated.jpg') img.crop(0, 0, 100, 100).save('cropped.jpg') # Transformations can be chained data = (img.scale(320, 240) .rotate(90) .flip('horizontal') .as_blob()) # jpegtran can transform the image automatically according to the EXIF # orientation tag photo = JPEGImage(blob=requests.get("http://example.com/photo.jpg").content) print photo.exif_orientation # "6" (= 270°) print photo.width, photo.height # "4320 3240" corrected = photo.exif_autotransform() print corrected.exif_orientation # "1" (= "normal") print corrected.width, corrected.height # "3240 4320"
有关详细信息,请参阅API Reference。
基准
所有操作均在3.4GHz i7-3770上完成,内存16GiB,转速7200RPM 具有以下2560x1920 8bit rgb jpeg的硬盘:
http://upload.wikimedia.org/wikipedia/commons/8/82/Mandel_zoom_05_tail_part.jpg
Wand Py和Pil都是用最快的缩放算法运行的, 对于wand py,这意味着使用Image.sample而不是Image.resize 对于pil,最近邻过滤器用于Image.resize 打电话来。
许可证
麻省理工学院许可证(MIT)
版权所有(C)2014 Johannes Baiter<;johannes.baiter@gmail.com>;
兹免费准许任何人取得 本软件和相关文档文件(“软件”),用于处理 不受限制的软件,包括但不限于 使用、复制、修改、合并、发布、分发、再授权和/或销售副本 以及允许向其提供软件的人员 因此,必须满足以下条件:
上述版权公告及本许可公告须包括在 软件的拷贝或大部分。
本软件按“原样”提供,无任何形式的保证,明示或 默示的,包括但不限于适销性保证, 适合特定目的和不侵权。在任何情况下 作者或版权所有者应对任何索赔、损害或其他 责任,无论是在合同诉讼、侵权诉讼或其他诉讼中, 不属于或与本软件有关,或使用或进行其他交易