Search code examples
pipestdgraphicsmagick

graphicsmagick - how to pipe two commands using standard in- & output


I would like to connect two different graphicsmagick commands using pipe, just as an example create a tiled image and after this is done add a border. What i understood from the manual "-" should be used as standard input or output, so this is what i tried:

gm montage -geometry +20+20 -tile 2x2 /home/pi/*.jpg - | gm convert -border 150x150 - /home/pi/test.jpg 

But for reasons i don't understand it breaks with this error message:

gm montage: No encode delegate for this image format (-) [No such file or directory].

Any idea what I'm doing wrong? Any hint would be highly appreciated...


Solution

  • Try specifying a file-type to send through stdin/stdout, such as MIFF (Magick Image File Format) which will preserve all meta-data and losslessly-encode the image in the pipe:

    gm montage -tile 2x2 *.jpg miff:- | gm convert miff:- -border 150x150 result.png
    

    You can also use PNG:- or JPEG:-, by the way - it's just that MIFF is best.