ImageMagick to Resize, Convert and Modify Images

Posted under » Linux on 09 November 2017

First of all you must install it. A simple application. 95 is the compression level.

convert anoneh.png -quality 95 anoneh.jpg

Mostly I use it for resizing images.

convert sample.png -resize 200x100 sample.png

We've used the same file name here, so ImageMagick will overwrite the original file

ImageMagick will try to preserve the aspect ratio if you use this command. It will alter the image to fit within a 200×100 area, but the image may not be exactly 200×100. If you want to force the image to become a specific size – even if it messes up the aspect ratio – add an exclamation point to the dimensions.

convert sample.png -resize 200x100! sample.png

You can also specify a specific width or height and ImageMagick will resize the image to that width or height while preserving the aspect ratio. The following command will resize an image to a width of 200.

convert sample.png -resize 200 sample.png

The following command will resize an image to a height of 100.

convert sample.png -resize x100 sample.png

Rotating an Image. ImageMagick can quickly rotate an image. The following command takes an image named anoneh.jpg, rotates it by 90 degrees and saves the rotated image as anoneh-rotated.jpg.

convert anoneh.jpg -rotate 90 anoneh-rotated.jpg

There are other commands but the above are what I use often.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data