Useful Imagemagick Commands
11 Jul 2016Imagemagick is one of those tools that’s there on literally every developers computer. It’s such a nifty and powerful tool, there’s so much you can do with it.
Imagemagick is a suite of command line tools that can edit, create and convert various image formats. Here’s a few commands I use regularly.
Combine two images together
This takes a.png and b.png and combines them horizontally to create c.png. For best results, make sure both the images are of same or comparable ratios.
To combine them vertically,
You can even combine images of different types (like a PNG and a JPG)!
Resizing images
Easily resize images by providing the width and height values. If you attempt to resize your images to a larger ratio, they will often loose quality and appear pixelated. Resize always seeks to preserve your aspect ratio even if given vales do not comply.
Blurring images
Add blur effects to your images quickly with this. The first value controls the radius of your blur, while the second value controls the strength. As a quick rule of the thumb, increase the second value to increase the blurriness.
Converting Videos to GIFs
I’ll admit it, I’ve used this far more times that anything else here. Who doesn’t love a bit of Reddit karma?
Making your white PNGs transparent
I’ve used this a million times. If you ever convert a JPG image to a PNG, you’ll notice the whites aren’t transparent, which ultimately ruins the purpose of a PNG. Use this command to make the white parts of your PNG transparent. The fuzz parameter is to smoothen out the conversion. Use a smaller value to keep the conversion closer to true white, or a larger value to allow more variation from white to become transparent.
Grayscale your images
That’s it! Simple as pie.
Square out your uneven images by adding white padding
Define the size of the PNG you’re converting in the png:size=wxh block. Here, w is the width and h is the height of the image. In the -thumbnail block, define the resultant thumbnail dimensions.
That’s it for now! I’ll keep updating this post as and when I find more useful commands.