Fuji
Fuji

Reputation: 15

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?

Upvotes: 1

Views: 1489

Answers (2)

jcupitt
jcupitt

Reputation: 11179

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.

Upvotes: 3

Glenn Randers-Pehrson
Glenn Randers-Pehrson

Reputation: 12445

With either ImageMagick or GraphicsMagick you can speed up PNG encoding by using a lower "-quality" instead of accepting the default quality==75. This will trade compression performance (file size) for speed. Try -quality 40 for line art, or -quality 41 for photos. Here are some results for a JPEG out of my camera, using ImageMagick-7.0.3-8 built with libpng-1.2.54:

glenn.rp> time magick D*88.JPG d88-q75.png
real    0m13.494s user  0m11.252s sys   0m2.060s
glenn.rp> time magick -quality 41 D*88.JPG d88-q41.png
real    0m7.377s user   0m4.728s sys    0m1.908s
glenn.rp> time magick -quality 40 D*88.JPG d88-q40.png
real    0m3.842s user   0m3.200s sys    0m0.584s
glenn.rp> ls -lt d88*
-rw-rw-r-- 1 glennrp glennrp 24352041 Nov 29 15:45 d88-q40.png
-rw-rw-r-- 1 glennrp glennrp 17072518 Nov 29 15:45 d88-q41.png
-rw-rw-r-- 1 glennrp glennrp 15788794 Nov 29 15:44 d88-q75.png

Upvotes: 0

Related Questions