Image Manipulations With Imagemagick
We’ve mentioned it before when we talked about progressive jpegs. Knowing some basic commands can save you time and allow you to stay in the terminal.
To install on Linux:
To install on Mac:
There are two commands that come out of the box when you install ImageMagick, convert mogrify and they both generally take the same arguments. Convert transforms the image and creates a new one and mogrify replaces the image in place. With these examples we’ll show them being used with both commands, but you can use them interchangeably.
To resize an image
It might be useful to add in the -gravity center
flag as well with the above command.
Trim whitespace from an image
Note that ImageMagick will maintain aspect ratio so to enforce the resolution strictly you can add in a exclamation symbol:
To reduce the quality and the image size you can pass in the quality
flag:
Convert a PNG to a JPG:
Create a collage of images by using the montage command:
Change colors in an image:
Create a favicon
We used this on Medium and this guide on Hackernoon to compile these commands. Read more about ImageMagick in the docs.