ImageMagick

index
|- convert -|- imdisplay -|- montage -|

2011-04-03: Minor update. The latest version per the ImageMagick site is version 6.6.9-3, but not installed since I do not use it that often. I also have version 6.3.7 2010-02-12 installed in my Ubuntu 8.04 LTS (linux) distribution, where perhaps the most used is 'identify', to get information about an image.

2007.08.09: I recently downloaded and installed ImageMagick, and this page is just some personal initial finding, as I try to discover how to use the powerful command line tools it offers.

Download and Install

From their site - http://www.imagemagick.org/script/index.php -> Binary Releases -> Windows, I chose to install ImageMagick-6.3.5-5-Q16-windows-static. I chose the 'static' because I do not have any need to utilize their DLL (shared library) Application Programming Interface (API) at this time.

They offered a Q8 and a Q16 version, and at this time not exactly understanding what this signifies, I chose the Q16 - at 16 bits-per-pixel ...

Running this EXE installed ImageMagick in C:/Program Files/ImageMagick-6.3.5-Q16, and I allowed it to modify the environment so this path was added into my PATH variable, so each of the EXE files installed can be run from the command line.

The list of EXE programs is/was, with a brief description from their site :-

animate animate an image sequence on any X server.
compare mathematically and visually annotate the difference between an image and its reconstruction.
composite overlap one image over another.
conjure interpret and execute scripts written in the Magick Scripting Language (MSL).
convert convert between image formats as well as resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more.
dcraw  
display display an image or image sequence on any X server.
hp2xx  
identify describe the format and characteristics of one or more image files.
imdisplay a small WIN32 GUI application that will read and display, they say over 100 formats.
import save any visible window on an X server and outputs it as an image file. You can capture a single window, the entire screen, or any rectangular portion of the screen.
mogrify resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more. Mogrify overwrites the original image file, whereas, convert writes to a different image file.
montage create a composite image by combining several separate images. The images are tiled on the composite image optionally adorned with a border, frame, image name, and more.
mpeg2dec  
mpeg2enc  
stream a lightweight tool to stream one or more pixel components of the image or portion of the image to your choice of storage formats. It writes the pixel components as they are read from the input image a row at a time making stream desirable when working with large images or when you require raw pixel components.
unins000 to un-install the suite.

Then the trick was to discover what each would do ;=))

top


convert

As perhaps expected, convert -help yields an enormous list of options. The most interesting is -resize geometry ... Here are some examples working on an image identified as follows :-

C:\...>identify DSCN0001.JPG
DSCN0001.JPG JPEG 1600x1200 1600x1200+0+0 DirectClass 8-bit 842.34kb 0.094u 0:01
C:\...>convert -resize 50x50 DSCN0001.JPG temp2.jpg
temp2.jpg JPEG 50x38 50x38+0+0 DirectClass 8-bit 8.66602kb
C:\...>convert -resize 100x100 DSCN0001.JPG temp2.jpg
temp2.jpg JPEG 100x75 100x75+0+0 DirectClass 8-bit 11.7832kb
C:\...>convert -resize 640x640 DSCN0001.JPG temp2.jpg
temp2.jpg JPEG 640x480 640x480+0+0 DirectClass 8-bit 130.768kb
C:\...>convert -resize 1200x1200 DSCN0001.JPG temp2.jpg
temp2.jpg JPEG 1200x900 1200x900+0+0 DirectClass 8-bit 397.375kb 0.063u 0:01
C:\...>convert -resize 1600x1600 DSCN0001.JPG temp2.jpg
temp2.jpg JPEG 1600x1200 1600x1200+0+0 DirectClass 8-bit 723.574kb 0.094u 0:01

This indicates that the aspect ratio of the original image is fully maintained. That is, even though a 'geometry' of say 100x100 was used, the resultant 'thumb' was 100x75. This implies a 'normal' resizing algorithm of something like the following is being used by the 'convert' application :-

   $thumb_size = 100;
   $ratio = $img_x / $img_y;
   if( $ratio > 1.0 ) {
      $new_img_x = $thumb_size;
      $new_img_y = round( $thumb_size / $ratio );
   } else {
      $new_img_x = round( $thumb_size * $ratio );
      $new_img_y = $thumb_size;
   }

Also, the 'resize' value can be expressed as a percentage, like :-

C:\...>convert -resize 50% DSCN0001.JPG temp2.jpg
temp2.jpg JPEG 800x600 800x600+0+0 DirectClass 8-bit 193.381kb
C:\...>convert -resize 40% DSCN0001.JPG temp2.jpg
temp2.jpg JPEG 640x480 640x480+0+0 DirectClass 8-bit 130.768kb

One example not tried - suppose you want to convert 1.jpg, 2.jpg, 3.jpg, 4.jpg, and 5.jpg in your current directory to a GIF animation. Then this simple command does the trick :-

convert *.jpg images.gif

And conversely, you wanted to extract the first image from a GIF :-

convert images.gif[0] 1.jpg

Inline Image Resize - It is sometimes convenient to resize an image as they are read. Suppose you have hundreds of large JPEG images you want to convert to a sequence of PNG thumbnails :-

convert *.jpg -resize 120x120 thumbnail%03d.png

Here all the images are read in and subsequently resized, and written out. It is faster and less resource intensive to resize each image as they are read with the following, but I found this tended to 'crash' in the XP command prompt :-

convert *.jpg[120x120] thumbnail%03d.png

Of course, to process a complete folder, and output the 'thumbs' to another folder using the same file name, the powerful XP command prompt 'for' command can be used. The following, when placed in a batch file, would process all the *.jpg in one folder, '..\tempb\images', and output a 'thumb' of the same name to another folder, 'temp' :-

for %%I in (..\tempb\images\*.jpg) do convert -resize 150x150 "%%I" "temp\%%~nI.jpg"

Note the use of inverted commas around the file names, in case there is a space in the name, and the use of the %~nI modifier to extract just the file name from the command.

convert seems a very powerful, and easy to use command line application.

top


imdisplay (display)

This was easy! 'imdisplay' is a small GUI application that will read and display, they say over 100 formats. The 'display' seems only for unix/linux, in that it seeks the X-windows server! After the install they suggest running a small set of commands to verify the installation :-

  convert logo: logo.gif
  identify logo.gif
  imdisplay logo.gif

The convert utilizes a built-in 'logo' from the command 'logo:', and writes it to logo.gif. identify gives the details of the logo.gif as -

logo.gif GIF 640x480 640x480+0+0 PseudoClass 256c 8-bit 37.4414kb

And the imdisplay loads that GIF file into a GUI display application.

montage

This is a cool application to join a bunch of say JPG files, into an index - a montage of images. The site gives an example like the following to collect a set of JPG files into a single sheet :-

montage  '*.jpg' -geometry 50x50+2+2  image_index.gif

The single inverted commas (') are only for unix/linux, to stop the command shell expanding it to a list of files instead of montage doing that. They must be left out, or double inverted commas (") used in the windows command shell.

This will generate an image index of all the JPG images in the local folder, and write it out to image_index.gif. The 50x50 controls the size of each, but it seems the aspect ratio is maintained. Not sure what the +2+2 does, although montage -help outputs :-

 -geometry geometry   preferred tile and border sizes

So perhaps this is the border sizes? And note the 'geometry' is only the 'preferred' tile size, since the aspect ratios of the original images is maintained.

top


checked by tidy  Valid HTML 4.01 Transitional