Aug 292010
 

ImageMagick Usually when we talk about programs for editing images we think to graphic programs such as The Gimp or photoshop, but they are not the only alternative.

ImageMagick is a suite of programs that you can use from command line to change and transform images, may seem more uncomfortable but it is actually a very powerful option to process many images in a short time or include image processing programs in web or bash scripts.



Here are some useful example to use these commands, the first we’ll use is convert:

To get started, lets convert an image in the JPEG format to PNG:

$magick> convert rose.jpg rose.png

Next, we reduce the image size before it is written to the PNG format:

$magick> convert rose.jpg -resize 50% rose.png

Convert from PNG to JPG. Use “-quality” for compression/quality (From 20 very low quality, to 100 original quality)and “-scale” to reduce the size.

$magick> convert -scale 50% -quality 80% old.png new.jpg

Here I give a polaroid look to a photo thumbnail. The image is looking up the spiral staircase (downward), inside the Arc de Triumph, Paris. It is a very long staircase!.

$magick> convert spiral_stairs_sm.jpg -thumbnail 120×120 -bordercolor white -background black +polaroid poloroid.png

This operator is very complex, as it adds border (as per the “-bordercolor” setting), ‘curls’ the paper, and adds a inverse curl to the shadow. The shadow color can be controlled by the “-background” color setting.

Convert a sequence of images (dna.1 dna.2, etc …) in an animated gif with a delay between one frame and another 20-hundredths of a second.

$magick>convert -delay 20 dna.* dna.gif

But the real strength of the convert command can be seen in a small bash script, suppose you want to convert all jpg files in the current directory and subdirectories to png

$magick>find . -name “*png” | xargs -l -i basename -s “.png” “{}” | xargs -l -i convert -quality 85% “{}.png” “{}.jpg”

The “-l” makes it process one line at a time. The “-i” makes the “{}” to stand for file name. The “basename -s” strips the suffix.

Mogrify: You can edit an image or a sequence of images. The possibilities are virtually endless, you can change size, color depth, you can rotate images, etc … Beware because the default behavior is to delete the original file, if you want keep the originals use convert

Converts all jpg files in png format.

$magick> mogrify -format png *.jpg

Reduces the width and height of 50%.

$magick> mogrify -format png *.jpg

Reduces the size of all JPG images in the current folder so that the longest side is 200 pixels., Maintaining the proportions.

$magick> mogrify -resize 200×200 *.jpg

Display is the only one who has fully graphical interface. The menu, which is activated by clicking within the window that appears after launching in a graph “display” has all those options otherwise active with other textual tools. You just have to navigate through menus to discover the available options. Unfortunately missing entirely visual feedback, a preview of the actions undertaken. If you do not know what to do and to what extent, becomes an extremely complex and frustrating to use (the same goes for other instruments).

Import is used to capture full screen or screens for windows or parts of them on the screen. After typing “import” a cross will appear in a console, just click in a window or on the desktop and wait a little bee beep to get a snapshot. If you are interested in parts of the screen just move where you want to carry the cross, left-click and hold to drag the cursor cross to where you want. If no additional options are given the “snapshot” of the screen will be saved in the MIFF format.

Animate: take the number of images passed as argument and displays them on screen as an animation. Do not save anything to disk.

$magick> animate -delay 100 immagine1.miff immagine2.miff immagine3.gif

Identify: to identify some characteristics of the file: format, size, number of colors and more. If you add the -verbose: “identify-verbose” will show other information including any comments.

Finally, I recommend these movies where ImageMagick is shown in action

Popular Posts:

Flattr this!

  One Response to “ImageMagick howto”

  1. […] quick look at ImageMagick Filed under: Linux — 0ddn1x @ 2010-09-07 19:20:55 +0000 http://www.linuxaria.com/article/guida-a-imagemagick Leave a Comment TrackBack […]

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*