 <?xml version="1.0" encoding="UTF-8"?>

 <?xml-stylesheet
 type="text/xsl"
 href="C:\Documents and Settings\Administrator\My Documents\Articles\1 -
 Templates\dw-document-html-2.1.xsl"?>

 <dw-document
 xmlns:dw="http://www.ibm.com/developerWorks/"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="http://dw.raleigh.ibm.com/developerworks/library/schema/2.2/dw-document-2.2.xsd">

 <dw-article
 toc="auto"
 ratings="auto"
 level="1"
 localsite="worldwide"
 related_contents="auto">

 <id
 domino-uid=""
 content-id=""/>

 <meta name="keywords"
 content="IBM, developerWorks, Linux, Michael Still, image, raster,
imagemagick, convert, rotate, scale, thumbnail, resize, artistic, graphic,
graphics, manipulation, conversion, photos, rounded corners, superimpose,
logo, logos, TODOCHECKTHESE"/>

 <meta name="Last update" content="150204 nm"/>

 <content-area name="linux"/>

<title>Even more graphics from the command line</title>
<subtitle>Tips and tricks for using ImageMagick on Linux</subtitle>

 <forumurl
 url=""/>

 <download-feature
 downloadtype="code"
 filename=""
 url-ftp=""/>

 <pdf
 url=""
 size="xx KB"/>

 <author
 jobtitle="Senior Software Engineer"
 email_cc="youngt01@us.ibm.com"
 email="mikal@stillhq.com"
 company="TOWER Software">
 <bio>Michael has been working in the image processing field for several
years, including a couple of years managing and developing large image
databases for an Australian government department. He currently works for
TOWER Software, which manufactures a world-leading EDMS and Records
Management package named TRIM. Michael is also the developer of Panda, an
open-source PDF generation API, as well as a bunch of other Open Source
code.</bio>
 <img src="" width="64" height="80"/>
 <name>Michael Still</name>
 </author>

 <date day="15" month="03" year="2004"/>

 <date-updated day="15" month="3" year="2004"/>

 <abstract>There's nothing quite like command-line tools for handling large batches of tasks, and image manipulations are no exception. Web developers and administrators will appreciate the ability to handle large numbers of files easily, either at the command line or in scripts. Programmer Michael Still presents more examples of the ImageMagick suite, this time demonstrating how to put cool curved corners on your images, a variety of different frames and borders, converting to and from Adobe's PDF format, and how to extract all the images from multiple page file formats. TODOUPDATE</abstract>

 <column-info
 col-name=""
 col-icon="column_icon.gif"/>

 <docbody>

 <column-info
 col-name=""
 col-icon="column_icon.gif"/>

 <docbody>

<p>This is the third article that IBM DeveloperWorks has published on the ImageMagick suite of command line tools. This article aims to wrap up the loose ends left by the last two articles, and assumes that you have read those articles. It also discusses functionality which builds on that discussed in those articles. I recommend that if you haven't read them yet, now is a good time to check them out. TODOURLSTOOLDARTICLES</p>





<heading refname="" type="major" toc="yes" name="" alttoc="">Montages</heading>

<p>One of the cool things you can do with ImageMagick is build montages of images. This has come in handy for the writing of both this article and the previous one in this series. I also find it useful to generate "contact sheets" for images from my digital cameras for instance.</p>

<p>You create montages with ImageMagick using the <b>montage</b> command. Here's a quick example invocation, as well as what it produces:</p>

<p>
<code type="inline">
montage waterfall-* montage.jpg
</code>
</p>

<p>Produces the picture:</p>

<figure>        
<heading refname="" type="figure" toc="no" name="" alttoc="">Figure TODO. The default montage output</heading>
<img src="montage-1.jpg" width="TODO" height="TODO" alt="A montage of waterfall pictures"/>
</figure>

<p>You can exhert more control over the montage than this however. If you use the <i>-geometry</i> parameter, then you can specify the maximum size of the individual images in the montage, as well as the spacing between the images.</p>

<p>
<code type="inline">
montage -geometry 80x80+5+5 waterfall-* montage.jpg
</code>
</p>

<p>Which specifies that each image should be no more than 80 by 80 pixels, and have a horizontal and vertical spacing of 5 pixels. It gives us:</p>

<figure>        
<heading refname="" type="figure" toc="no" name="" alttoc="">Figure TODO. Geometrized montage output</heading>
<img src="montage-2.jpg" width="TODO" height="TODO" alt="A montage of waterfall pictures"/>
</figure>

<p>You can also specify the number of images that appear in a given row. For example:
</p>

<p>
<code type="inline">
montage -geometry 80x80+5+5 -tile 2x3 waterfall-* montage.jpg
</code>
</p>

<p>Which specifies that there should be three rows of two images each.</p>

<figure>        
<heading refname="" type="figure" toc="no" name="" alttoc="">Figure TODO. Tiled montage output</heading>
<img src="montage-3.jpg" width="TODO" height="TODO" alt="A montage of waterfall pictures"/>
</figure>

<p>There are many other montage options available, including changing the background color and drawing frames around the images. I recommend that you checkout the <b>montage</b> man page for more information.</p>







<heading refname="" type="major" toc="yes" name="" alttoc="">Animated images</heading>

<p>As mentioned in <a href="TODOURL">TODOTITLE</a>, ImageMagick easily copes with file formats which can store more than one image. When you think about it, one of the most interesting uses of such a format is animations. For example, animated GIFs are just a series of GIF images which are displayed at 25 frames per second or so.</p>

<p>ImageMagick does quite well at handling these multiple image formats, including the animated ones. For example, consider a scenario in which we have several images which are the frames of an animation. These might have been produced in your favourite graphics editor, or generated in some other way which is outside the scope of this article. For these various animation examples, we'll use some simple TIFF images which I produced programmatically.</p>


<sidebar>
<heading refname="" type="sidebar" toc="no" name="" alttoc="">Generating animation frames programatically</heading>
<p>The frames for these animations were generated with <a href="http://www.stillhq.com/extracted/tiff-motion/">some sample code from my website</a>. This sample code uses libtiff. For more information on how to writing imaging code using libtiff, checkout my IBM DeveloperWorks articles on libtiff programming: <a href="http://www-106.ibm.com/developerworks/linux/library/l-libtiff/">graphics programming with libtiff</a> and <a href="http://www-106.ibm.com/developerworks/linux/library/l-libtiff2/">graphics programming with libtiff, part 2</a>.</p> 

<p>The secret to generating your own animations programmatically is to remember that each frame should only be very slightly different from the previous frame. If the frames are too different, then the animation will look jerky and confusing.</p>
</sidebar>

<p>My program produced a bunch of images named output-&lt;number&gt;.tif, which are just a simple line moving around a rectangle. Here's a couple of snapshots that I put into a single image file using the <b>montage</b> command as described above.</p>

<figure>        
<heading refname="" type="figure" toc="no" name="" alttoc="">Figure TODO. A few frames from the animation</heading>
<img src="sequence.jpg" width="TODO" height="TODO" alt="A few of the images from the animation"/>
</figure>

<p>How do we convert these many image files into an animated single image? Well, if the destination file for the convert command is one which supports multiple images in one file, then all will be well.</p>

<sidebar>
<heading refname="" type="sidebar" toc="no" name="" alttoc="">Not all file formats which support more than one image in a file are animations</heading>
<p>While trying not to make this description too confused, it should be noted that not all file formats which support more than one image per file are animations. TIFF and PDF for instance both support multiple images, but they are more like pages than frames in an animation.</p>

<p>The same technique as described here, if applied to one of these file formats will do the right thing and produce a multi-page document.</p>
</sidebar>

<p>Here's an example:</p>

<p>
<code type="inline">
convert output-* ani.gif
</code>
</p>

<p>Which gives us this silly little animation:</p>

<figure>        
<heading refname="" type="figure" toc="no" name="" alttoc="">Figure TODO. Our animation</heading>
<img src="ani.gif" width="TODO" height="TODO" alt="An animated gif"/>
</figure>

<p>Using the <i>-combine</i> command line arguement to <b>convert</b> will have the same effect as the example above, while being a little bit more explicit. Using the <i>-loop</i> command line arguement will add the Netscape looping extensions to your GIF animations, which will be handy for creating those annoying never ending advertisements for your website.</p>







<heading refname="" type="major" toc="yes" name="" alttoc="">Extracting sub images</heading>

<p>Now that we've got this image file which is made up of lots of frames, let's now explore how to extract frames from the file. <b>convert</b> lets you sepcify a sub image with the following syntax:</p>

<p>
<code type="inline">
convert ani.gif[42] frame42.gif
</code>
</p>

<p>You might need to use quotes around the input image and frame number specification to stop your shell from trying to interpret the frame specification as some sort of shell construct. This will vary based on the shell that you're using at the time.</p>

<p>Being able to extract sub images is actually a really useful feature. For example, it makes it really easy to extract single frames from all those home movies that you have floating around, assuming that you have the right delegate installed for the image format that you're trying to extract the frames from.</p>

<sidebar>
<heading refname="" type="sidebar" toc="no" name="" alttoc="">Delegates</heading>
<p>ImageMagick needs help reading and writing from all of those image formats which it supports. These various formats are supported by ImageMagick using things called delegates. Delegates are simply other packages which support a particular image format. For instance, the TIFF support in ImageMagick is done with the libtiff library discussed in some of my other IBM DeveloperWorks articles. This means that if libtiff is not installed on your system, then you'll get an error message.</p>

<p>An example of the sort of error message you'll see is what happens to me when I try to extract a frame from a MPEG compressed movie:</p>

<p>
<code type="inline">
mikal@challenger:~/watchme$ convert kids.mpg[4] output.jpg
sh: line 1: mpeg2decode: command not found
convert: Delegate failed `"mpeg2decode" -q -b "%i" -f -r -o3 "%u%%d"'.
convert: missing an image filename `output.jpg'.
mikal@challenger:~/watchme$ 
</code>
</p>

<p>Here it's telling me that I need to install a package which provides the mpeg2decode command line utility. Not all delegates are command line packages though, this error message could have easily specified the name of a library.</p>
</sidebar>
































</docbody>

<relatedlist>
<a href="http://www-106.ibm.com/developerworks/linux/library/l-libtiff/">Graphics programming with libtiff</a>
<a href="http://www-106.ibm.com/developerworks/linux/library/l-libtiff2/">Graphics programming with libtiff, Part 2</a>
<a href="http://www-106.ibm.com/developerworks/linux/library/l-graf/">Graphics from the command line</a>
<a href="http://www-106.ibm.com/developerworks/xml/edu/x-dw-xiactsvg-i.html">Interactive, dynamic Scalable Vector Graphics</a>
<a href="http://www.alphaworks.ibm.com/tech/tk4mpeg4">IBM Toolkit for MPEG-4</a>
<a href="http://www-106.ibm.com/developerworks/websphere/library/techarticles/0111_kemble/0111_kemble.html">Voice-Enabling Your Web Sites</a>
<a href="http://www-306.ibm.com/software/tivoli/products/web-site-analyzer/">IBM Tivoli Web Site Analyzer</a>
</relatedlist>

<resourcelist>
<ul>

 <li> ImageMagick is a collection of tools and libraries to read, write, 
and manipulate images in over 89 major formats. 
The <a href="http://www.imagemagick.org">ImageMagick</a> Web site is
an excellent resource, and offers downloads of the ImageMagick source
code. 
The <a href="http://www.imagemagick.org/www/utilities.html">Command-line
utilities</a> page gives more information on convert, mogrify, 
composite and other tools like compare and conjure, as well as 
their options -- it also gives a complete list of the 
file formats that are recognized by ImageMagick. </li>

<li>
You can also invoke ImageMagick capabilities from your favorite 
programming language, from C and Java to Perl and PHP. Check the list 
of <a href="http://www.imagemagick.org/www/apis.html">programming 
interfaces</a> for more information.
</li>

<li>
Learn even more at Anthony Thyssen's 
<a href="http://www.cit.gu.edu.au/~anthony/graphics/imagick6/">ImageMagick Examples</a> page.
</li>

<li>
The
<a href="">GIMP</a>, or GNU Image Manipulation Program, 
is a freely  
distributed piece of software suitable for such tasks as photo retouching,
image composition and image authoring.  It is released under
the GNU General Public License (GPL).
</li>

<li>
Many of the pictures in this article were taken during my recent trip to
<a href="linux.conf.au">linux.conf.au</a>.
</li> 

 <li>The <a
href="http://www.stillhq.com/extracted/article-imagingtoolsmore/corners">corners</a>
I used in the first example are available for download, I waive the copyright on these images (although I don't waive the copyright on the rest of the images in this article).
</li>

 <li>"<a
href="http://www-106.ibm.com/developerworks/linux/library/l-graf/">Graphics
from the command line</a>" (<i>developerWorks</i>, July 2003) is the first
article in the series and discusses how to thumbnail, rotate, apply
interesting graphical manipulations, and determine image information with
ImageMagick.</li>

 <li>"<a
href="http://www-106.ibm.com/developerworks/linux/library/l-libtiff/">Graphics
programming with libtiff</a>" (<i>developerWorks</i>, March 2002)
discusses black and white imaging concepts, with a particular focus on
TIFF images.</li>

 <li>"<a
href="http://www-106.ibm.com/developerworks/linux/library/l-libtiff2/">Graphics
programming with libtiff, Part 2</a>" (<i>developerWorks</i>, June 2002)
discusses color TIFF images, but also discusses important topics such as
which compression scheme is right for you.</li>

<li>
Scalable Vector Graphics (SVG) 
is an XML application language which describes 2D vector
  graphics
including 
 animation and scripting functionality. Get started with 
<a href="http://www-106.ibm.com/developerworks/xml/edu/x-dw-xiactsvg-i.html">Interactive, dynamic Scalable Vector Graphics</a> 
(<i>developerWorks</i>, February 2002).
</li>


<li>
The 
<a href="http://www.alphaworks.ibm.com/tech/tk4mpeg4">IBM Toolkit for MPEG-4</a>
is a set of Java classes and APIs with sample playback and MPEG-4 
generation applications. It's also one of the top downloads at 
alphaWorks -- check it out for yourself to see why!
</li>

<li>
Got pictures? Add voice to your Web site 
with  <a href="www.voicexml.org">VoiceXML</a>. Get started with the article,
<a href="http://www-106.ibm.com/developerworks/websphere/library/techarticles/0111_kemble/0111_kemble.html">Voice-Enabling Your Web Sites</a> 
(<i>developerWorks</i>, November 2001).
</li>

<li>
Got pictures <i>and</i> voice? Find out what impact it's having with 
<a href="http://www-306.ibm.com/software/tivoli/products/web-site-analyzer/">IBM Tivoli Web Site Analyzer</a>. IBM Tivoli Web Site Analyzer
captures, analyzes, stores and reports on 
Web site usage, 
health, integrity and site content, and 
provides essential metrics on visitor site interactions and the site's
overall performance
</li>


 <li>
 Find more resources for Linux developers in the <a
 href="http://www.ibm.com/developerworks/linux/">developerWorks Linux
 section</a>.
 </li>

 <li>
 You'll find a wide selection of books on Linux at the <a
 href="http://devworks.krcinfo.com/WebForms/ProductList.aspx?Search=Category&amp;id=300&amp;parent=Linux">Linux section</a> of the Developer Bookstore.
 </li>

    </ul>
  </resourcelist>

</dw-article>
</dw-document>