Search code examples
imagemagickimage-resizinggraphicsmagickimage-conversion

Command-line image converter\resizer


I'm looking for a command-line image converter/resizer.

What i need to do is convert bitmap and tiff files into png files as well as creating a thumbnail. The images are relatively large. The largest is approximately 13,000 x 10,000 pixels and around 200mb.

I've tried ImageMagick. It used too much memory, was too slow, and couldn't handle the largest files without using disc cache making it unbearably slow.

Currently I'm using GraphicsMagick which uses less memory and can handle the larger files, but it is still a little slow. Around 15s per image.

Are there any other programs out there that could maybe offer a little better performance?


Solution

  • You could try libvips. It's a streaming image processing library, so it's able to read the input, process, and write the output as a single pipeline, with no separate loading phase and no temporary files. It's got a fancy threaded IO system too, so performance is good and memory use is low.

    I timed it on this machine (imac with ImageMagick 6.9.6-3 Q16, gm 1.3.25, vips 8.4.2):

    $ vips black test.tif 13000 10000 --bands 3
    $ ls -l test.tif
    -rw-r--r--  1 john  staff  390000854 22 Nov 09:43 test.tif
    

    So that's a 13000 x 10000 3-band, 8 bit uncompressed TIFF. With vipsthumbnail, the image shrinker that comes with vips, I see:

    $ /usr/bin/time -l vipsthumbnail test.tif -s 128x128 -o small.png
        0.54 real         0.42 user         0.11 sys
    77635584  maximum resident set size
    

    I ran three times and picked the fastest, so that should just be a test of vipsthumbnail and not my disk system. That's 0.54s real time, 77MB of peak memory.

    With convert I see:

    $ /usr/bin/time -l convert test.tif -resize 128x128 small.png
        4.87 real         4.28 user         0.55 sys
    1432182784  maximum resident set size
    

    Again, fastest of three runs, 4.87s real time, 1.4gb memory. GraphicsMagick is a little faster, I see:

    $ /usr/bin/time -l gm convert test.tif -resize 128x128 small.png
        3.95 real         3.41 user         0.51 sys
    1264369664  maximum resident set size
    

    So 3.95s real, 1.2gb peak memory.

    So on this test, libvips is 7x faster and uses 15x less memory than graphicsmagick.

    libvips is a standard part of most linuxes, it's in homebrew and macports, and there are 64-bit windows binaries on the vips website.