Search code examples
imagemagickimagemagick-convertgraphicsmagick

Multiple converts from one source using imagemagick


Is it possible to have one source and from that have 2 types of processed images with different configurations? (and not to read the source image twice)?

Something like

convert input.jpg -resize 300 output1.jpg -resize 600 output2.jpg

Solution

  • Sure, use an intermediate -write like this, and do the big one first:

    convert input.jpg -resize 600 -write im600.jpg -resize 300 im300.jpg
    

    Or, if you want to start afresh with each operation:

    convert input.png \
      \( +clone -resize 300 -write result300.jpg \) \
      \( +clone -resize 600 -write result600.jpg \) null:
    

    If using GraphicsMagick, I am not sure if there is a better way than the following:

    #!/bin/bash
    { echo convert input.png mpr:orig; 
      echo convert mpr:orig -resize 300 result300.jpg;
      echo convert mpr:orig -resize 600 result600.jpg; } | gm batch -prompt off
    

    This is a slightly different version that only invokes convert twice:

    #!/bin/bash
    cat - <<EOF | gm batch -prompt off
    convert input.png -write mpr:orig -resize 300 result300.jpg
    convert mpr:orig -resize 600 result600.jpg
    EOF