Resizing Images

Resizing Images

The convert command can also quickly resize an image. The following command asks ImageMagick to resize an image to 200 pixels in width and 100 pixels in height:

convert example.png -resize 200×100 example.png

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

resize

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 example.png -resize 200×100! example.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 example.png -resize 200 example.png

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

convert example.png -resize x100 example.png

Rotating an Image

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

convert howtogeek.jpg -rotate 90 howtogeek-rotated.jpg

If you specified the same file name, ImageMagick would save the rotated image over the original image file.

rotate

Leave a Reply

Your email address will not be published. Required fields are marked *