Search code examples
imagemagickcropimagemagick-convertgraphicsmagick

How-to improve the performance of cropping images with ImageMagick?


convert image.png -crop 256x256 +repage +adjoin out_%d.png

takes for a large image 20000x8000 aprox 114 seconds. (about 4000 256x256 pngs are generated)

Are there any imagemagick options to improve the speed of cropping?


Solution

  • One thing you can do is be sure to use a "Q8" build of ImageMagick rather than the default "Q16", if your original images have 8-bit samples. Each pixel occupies 8 bytes (16-bit R, G, B, A) even if it's just a black-and-white drawing. Using Q8 cuts that in half. You can change the behavior with the "-limit" option, to use more memory instead of disc.

    The -limit option is described in the "options" documentation for ImageMagick.

    You can improve the speed of PNG compression by using "-quality 1" which selects Huffman-only compression and the "sub" PNG filter. If you know that the image has fewer than 256 colors, "-quality 0" might be more effective (the time consumed will be about the same but the resulting file will be smaller).