Efficiently generating thumbnails with ImageMagick and convert

前端 未结 5 1413
栀梦
栀梦 2020-12-25 09:06

I\'m looking to efficiently generate various sized thumbnails with ImageMagick\'s convert utility in Python. Some of my image files are quite large (~15MB JPGs).

One

5条回答
  •  醉话见心
    2020-12-25 09:40

    I'm thumbnailing ~50MB JPG files. The one option which made the biggest difference (~5x speedup) was "-define jpeg:size 128x128" before the input filename. The example given here:

    http://www.imagemagick.org/Usage/formats/#jpg_read

    ...made a huge difference:

    convert -define jpeg:size=128x128 jpeg_large.jpg -thumbnail 64x64  jpeg_thumbnail.jpg
    

    -define jpeg:size allows ImageMagick to read in only as much data as it needs from disk, which greatly reduces load time for very large images.

    As the linked page suggests, use a jpeg:size= of twice your final thumbnail size to avoid aliasing.

    The -thumbnail option, described here:

    http://www.imagemagick.org/Usage/resize/#thumbnail

    ...samples and strips the image, further speeding up the process.

提交回复
热议问题