Friday, March 11, 2011

How to resize image of the exact size from command line with help of ImageMagick

ImageMagick is a free software suite to create, edit, and compose bitmap images. It can read, convert and write images in a large variety of formats. Images can be cropped, colors can be changed, various effects can be applied, images can be rotated and combined, and text, lines, polygons, ellipses and Bézier curves can be added to images and stretched and rotated. In this post, I will show you how to use some of the basic commands from command line.

Below is an image with dimension 500*288

To resize it to smaller size of Dimension 100*100, you can browse to the folder where image is located, my image location is C drive, so I opened command prompt (working on Windows platform) and browse to C drive then use the command:
C:\>convert magic-tree.jpg -resize 100x100 small.jpg
 


magic-tree.jpg is my original image which I want to resize.
small.jpg is my final image created after resizing

But, you will find that the Dimension is not 100*100, instead it is 100*58. This is because its maintaining aspect ratio.

To ignore aspect ratio and to resize it to exact size, you have to use Ignore Aspect Ratio ('!' flag)
 


C:\>convert magic-tree.jpg -resize 100x100! small.jpg.

Similarly, you can resize the image of any size and any fomat like jpg, png etc.
RoR Guide & Solutions: Various options available in ImageMagick

No comments:

Post a Comment