MoonPoint Support Logo

 

Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
April
Sun Mon Tue Wed Thu Fri Sat
   
7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      
2025
Months
AprMay Jun
Jul Aug Sep
Oct Nov Dec


Sun, Jan 01, 2012 1:55 pm

Resizing an image from the command line

If you have the ImageMagick package installed on a Linux system or Mac OS X, you can use the convert tool that comes with it to resize an image from a shell prompt. ImageMagick is also available for Microsoft Windows systems, but I haven't tried it on a Microsoft Windows system.

To resize an image, one uses the -sample option for the convert tool as in the example below, which resizes an image, input.jpg, to 80 pixels wide and 40 pixels high, storing the result in output.jpg.

$ convert -sample 80x40 input.jpg output.jpg

You can also specify percentages of the original file size rather than a size in pixels.

convert -sample 25%x25% input.jpg output.jpg

Note: when you use the -sample option to specify the size of the output image in pixels, you may not get the exact sizes you specified for the width and height of the image. This is because ImageMagick considers the aspect ratio of the two sides of the image when it is resizing, keeping the aspect ratio of the new image the same as that of the previous image. So one of the values may not be the same as the number you put on the command line.

You can use the identify utility that comes with ImageMagick to obtain the width and height of an image (the width value is displayed first followed by the height).

$ identify example.png
example.png PNG 100x89 100x89+0+0 DirectClass 11kb

In the example above, the image is 100 pixels wide by 89 pixels high.

You can determine if ImageMagick and these associated tools are on the system by using the which command.

$ which identify
/usr/bin/identify
$ which convert
/usr/bin/convert

References:

  1. Graphics from the command line
    Flip, size, rotate, and more with ImageMagick
    By: Michael Still, Senior software engineer, Tower Software
    Date: July 16, 2003
    Linux - Technical resources for Linux programmers and system administrators

[/software/graphics/imagemagick] permanent link

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo