Saturday, 5 November 2011

Image Resizing Using Linux Command Line

Image resizing is one of those things in linux that should not be done using GUI. Better than GUI, there is a part of ImageMagick package for effective resizing of any image.

For resizing images, you need to have ImageMagick installed in your linux system. ImageMagick is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (about 100) including GIF, JPEG, JPEG-2000, PNG, PDF, PhotoCD, TIFF, and DPX. You can use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bezier curves.

For ubuntu and debian based distros, type the following in console for installation:
sudo apt-get install imagemagick

Now, to resize any image, we can either use mogrify or convert command(these commands are far more complex and useful than just resizing, check man mogrify for more details of their functionalities.) that is part of ImageMagick suite.

For example, to resize an image you can use the following command:

mogrify -resize 50% image_name.jpg

That would reduce the size to 50% of the original size.

To resize to certain pixel, you can specify the expected dimension as below:

mogrify -resize 800x600 image_name.jpg