快速的jpeg/jpg缩略图缩放,最小的烦扰和cpu开销。它利用libjpeg的特性,只需解码重建所需大小的图像所需的dct系数就可以加载图像。

epeg-cffi的Python项目详细描述


说明

An IMMENSELY FAST JPEG thumbnailer library API.

Why write this? It’s a convenience library API to using libjpeg to load JPEG images destined to be turned into thumbnails of the original, saving information with these thumbnails, retreiving it and managing to load the image ready for scaling with the minimum of fuss and CPU overhead.

This means it’s insanely fast at loading large JPEG images and scaling them down to tiny thumbnails. It’s speedup will be proportional to the size difference between the source image and the output thumbnail size as a count of their pixels.

It makes use of libjpeg features of being able to load an image by only decoding the DCT coefficients needed to reconstruct an image of the size desired. This gives a massive speedup. If you do not try and access the pixels in a format other than YUV (or GRAY8 if the source is grascale) then it also avoids colorspace conversions as well.

epeg源:https://github.com/mattes/epeg

此模块通过cffi提供python绑定。

用法

In [1]: import epeg
In [2]: thumbnail_data = epeg.scale_image(
    fname,   # Path to source JPEG image
    width,   # Desired thumbnail width
    height,  # Desired thumbnail height
    quality  # Desired quality, default: 75)

基准

魔杖

In [1]: from wand.image import Image
In [2]: %timeit Image(filename='/tmp/007.jpg'); img.sample(800, 600); _ = img.make_blob('jpeg')
1 loops, best of 3: 264 ms per loop

绒毛/枕头

In [1]: from PIL import Image
In [2]: %timeit Image.open('/tmp/007.jpg').resize((800, 600)).save('/tmp/foo_thumb.jpg')
1 loops, best of 3: 234 ms per loop

epeg

In [1]: import epeg
In [2]: %timeit epeg.scale_image('/tmp/007.jpg', 800, 600)
10 loops, best of 3: 101 ms per loop

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何表示1。。Java中的n关系   java在安卓应用程序中添加polaris viewer   Java字符串::replaceAll仅替换第一个出现(可能不正确的正则表达式)   java Tomcat/JBoss部署后脚本   如何在Heroku Java应用程序中运行发出web请求的周期进程   java如何以纳秒为单位证明算法的时间   Solaris上的java自定义ListCellRenderer(使用jre5)   java试图为我的播放器类测试块实现播放器重力(RealtutsGml平台教程)   c#消耗一个。带有java的net web服务未显示预期结果   java在KOI8\R中检索html   基于java图形的搜索与基于随机的搜索   java如何检查安卓设备上的可用空间?在SD卡上?