ImageMagick Input and Output

Using ImageMagick’s convert is pretty straightforward. For example, if you want to resize image you can use:

$ convert -resize 200x200 image.png small.png

Sometimes we want to use image on our standard input (STDIN), to let ImageMagick knowing where the image source is we can use:

$ cat image.png | convert -resize 200x200 - small.png

Pretty simple, right?

As you can see, we can supply filename to get the result as a file. If we want to set the output to standard output (STDOUT) then we can also use -:

$ cat image.png | convert -resize 200x200 - - > small.png

Yes, there is double dash, first one is for input, then second one is for output.

If you want to get different file format other than input one, you can do:

$ cat image.png | convert -resize 200x200 - jpg:- > small.jpg

That’s it.

If you prefer GraphicsMagick instead of ImageMagick, you can prepend convert with gm, so you’ll get:

$ gm convert -resize 200x200 image.png small.png

Both ImageMagick and GraphicsMagick are great choices. Choose one that fit your need (or taste).