My Favorite ImageMagick Convert Commands

Manipulate images from the command line.

ImageMagick is an amazing CLI image manipulation utility I have been using for 20 years. Here are some of the common PNG/JPG/etc commands I use.

Add solid background to the image

While keeping the original contents in the center. You need to know the output width / height. For example to make the output image width 600 pixels with white border on both sides use the command

1
convert input.png -background white -gravity center -extent 600 output.png

Combine several images into one row

Use +append to create a single row. Use -append to create a column.

1
convert image1.png image2.png image3.png ... +append output.png

Compute average image color

See Give browser a chance blog post.

Generate an image with solid color

1
2
3
4
5
6
# hex format
convert -size 100x100 xc:#ff00ff cyan.png
# bright green color used for background removal
convert -size 1920x1080 xc:#00ff00 green.png
# rgba format using quotes
convert -size 100x1000 'xc:rgba(255, 0, 255, 0.5)' cyan.png

Extend the image

Let's add transparent margins to an image and resize it while preserving the aspect ratio

1
2
3
4
convert in.png \
-background none +repage -gravity center \
-extent 3000x1506 +repage \
-resize 2000 out.png