100 Useful Command-Line Utilities

by Oliver; 2014

98. display, convert, identify

Note: display, convert, and identify are not default shell programs. You have to download and install them from ImageMagick, an awesome suite of command-line tools for manipulating images.

display is a neat command to display images right from your terminal via the X Window System:
$ display my_pic.png
identify gets properties about an image file:
$ identify my_pic.png 
my_pic.png PNG 700x319 700x319+0+0 8-bit DirectClass 84.7kb 
So, this is a 700 by 319 pixel image in PNG format and so on.

convert is a versatile command that can do about 8 gzillion things for you. For example, resize an image:
$ convert my_pic.png -resize 550x550\> my_pic2.png
Add whitespace around the image file my_pic.png until its 600px by 600px and convert it into gif format:
$ convert my_pic.png -background white -gravity center -extent 600x600 my_pic.gif
Do the same thing, but turn it into jpg format and put it at the top of the new image file (-gravity north):
$ convert my_pic.png -background white -gravity north -extent 600x600 my_pic.jpg
Change an image's width (in this case from 638 to 500 pixels) while preserving its aspect ratio:
$ convert my_pic_638_345.png -resize 500x my_pic_500.png
As a common use case, the ImageMagick commands are invaluable for optimizing images you're using on your websites. See How to Make a Website - Working with and Optimizing Images for Your Site for details.

<PREV   NEXT>