


  

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  



  

    

      

        
../index.html[ImageMagick] 
        

        
http://www.imagemagick.org/[sponsor] 
        

        
../index.html 
        
../index.html 
      

    

  


  

  


    

      

      
#mainSkip to page contents 

      
[
      
../index.htmlAbout ImageMagick       
../www/command-line-tools.htmlCommand-line Tools       
../www/api.htmlProgram Interfaces   
][
      
../www/install-source.htmlInstall from Source       
../www/binary-releases.htmlBinary Releases       
../www/resources.htmlResources   
][
      
../www/download.htmlDownload   
][
      
../www/links.htmlLinks   
][
      
../www/sponsors.htmlSponsors   
http://larscapes.com/Larscapes       
]
      


      

[ #anatomyThe Anatomy of the Command Line  | #inputInput Filename  | #settingImage Setting  | #operatorImage Operator  | #sequenceImage Sequence Operator  | #stackImage Stack  | #outputOutput Filename ]
The ImageMagick command line can be as simple as
  convert image.jpg image.png
or as complex as
  convert label.gif +matte \
    \( +clone  -shade 110x90 -normalize -negate +clone  -compose Plus -composite \) \
    \( -clone 0 -shade 110x50 -normalize -channel BG -fx 0 +channel -matte \) \
    -delete 0 +swap  -compose Multiply -composite  button.gif
Without knowing much about the ImageMagick command line, you can probably figure out that the first command converts an image in the JPEG format to one in the PNG format.  However, very few may realize the second, more complex command, gives a flat two-dimensional label a three-dimensional look with rich textures and simulated depth:  
../images/label.giflabel   
==>  
../images/button.gifbutton 
In the next sections we dissect the anatomy of the ImageMagick command line.  Hopefully, after carefully reading and better understanding how the command line works, you should be able to accomplish complex image-processing tasks without resorting to the sometimes daunting ../www/api.htmlprogram interfaces .
  
The Anatomy of the Command Line
The ImageMagick command line consists of
one or more required input filenames.zero, one, or more image settings.zero, one, or more image operators.zero, one, or more image sequence operators.zero, one, or more image stacks.zero or one output image filenames (required by ../www/convert.htmlconvert , ../www/composite.htmlcomposite , ../www/montage.htmlmontage , ../www/compare.htmlcompare , ../www/import.htmlimport , and ../www/conjure.htmlconjure ).You can find a detailed explanation of each of the constituent parts of the command line in the sections that follow.
  
Input Filename
ImageMagick extends the concept of an input filename to include: 1) filename globbing; 2) an explicit image format; 3) using built-in images and patterns; 4) reading an image from standard in; 5) selecting certain frames from an image;  and 6) selecting a region of an image.  Each of these extensions are explained in the next few paragraphs.
Filename Globbing  
In Unix shells, certain characters such as the asterisk (*) and question mark (?) automatically cause lists of filenames to be generated based on pattern matches. This feature is known as globbing.  ImageMagick supports filename globbing for systems, such as Windows, that does not natively supports it.  For example, suppose you want to convert 1.jpg, 2.jpg, 3.jpg, 4.jpg, and 5.jpg in your current directory to a GIF animation.  You can conveniently  refer to all of the JPEG files with this command:  convert *.jpg images.gif
Explicit Image Format  
Images are stored in a mryiad of image formats including the better known JPEG, PNG, TIFF and others.  ImageMagick must know the format of the image before it can be read and processed.  Most formats have a signature within the image that uniquely identifies the format.  Failing that, ImageMagick leverages the filename extension to determine the format.  For example, image.jpg tells ImageMagick it is reading an image in the JPEG format.  In some cases the image may not contain a signature and/or the filename does not identify the image format.  In these cases an explicit image format must be specified.  For example, suppose our image is named image and contains raw red, green, and blue intensity values.  ImageMagick has no way to automagically determine the image format so we explicitly set one:  convert -size 640x480 -depth 8 rgb:image image.png
Built-in Images and Patterns  
ImageMagick has a number of built-in ../www/formats.html#builtin-imagesimages  and ../www/formats.html#builtin-patternspatterns .  To utilize the checkerboard pattern, for example, use:  convert -size 640x480 pattern:checkerboard checkerboard.png
Standard In  
Unix permits the output of one command to be piped to another.  ImageMagick permits piping one command to another with a filename of –.  In this example we pipe the output of convert to the display program:  convert logo: gif:- | display gif:-
  
Here the explicit format is optional.  The GIF image format has a unique signature within the image so ImageMagick can readily recognize the format as GIF.Selecting Frames  
Some images formats contain more than one image frame.  Perhaps you only want the first image, or the last, or some number of images in-between.  You can specify which image frames to read by appending the image filename with the frame range enclosed in brackets.  Here our image contains more than one frame but we only want the first:  convert images.gif[0] image.png
  
Unix shells generally interpret backets so we must enclose the filename in quotes:  convert 'images.gif[0]' image.png
  
You can read more than one image from a sequence with a frame range.  For example, suppose you want the first four frames of an image sequence:  convert 'images.gif[0-4]' images.mng
  
Finally, you can read more than one image from a sequence, out-of-order:  convert 'images.gif[3,2,4]' images.mng
	
This reads the third image in the sequence, followed by the second, and then the fourth.Selecting an Image Region  
Raw images are a sequence of color intensities without additional meta information such as width, height, or image signature.  With raw image formats, you must specify the image width and height but you can also specify a region of the image to read.  In our example, the image is in the raw 8-bit RGB format and is 6000 pixels wide and 4000 pixels high.  However, we only want a region of 600 by 400 near the center of the image:  convert -size 6000x4000 -depth 8 'rgb:image[600x400+1900+2900]' image.jpg
  
You can get the same results with the ../www/command-line-options.html#extract–extract  option:  convert -size 6000x4000 -depth 8 -extract 600x400+1900+2900 rgb:image image.jpg
  
Image Setting
An image setting persists as it appears on the command line and may affect subsequent processing such as reading an image, an image operator, or when writing an image as appropriate.  An image setting stays in effect until it is reset or the command line terminates.  The image settings include:
../www/command-line-options.html#adjoin–adjoin  
../www/command-line-options.html#antialias–antialias  
../www/command-line-options.html#authenticate–authenticate  
../www/command-line-options.html#background–background  
../www/command-line-options.html#bordercolor–bordercolor  
../www/command-line-options.html#box–box  
../www/command-line-options.html#channel–channel  
../www/command-line-options.html#clip–clip  
../www/command-line-options.html#clip-path–clip-path  
../www/command-line-options.html#colors–colors  
../www/command-line-options.html#colorspace–colorspace  
../www/command-line-options.html#comment–comment  
../www/command-line-options.html#compress–compress  
../www/command-line-options.html#debug–debug  
../www/command-line-options.html#define–define  
../www/command-line-options.html#delay–delay  
../www/command-line-options.html#density–density  
../www/command-line-options.html#depth–depth  
../www/command-line-options.html#display–display  
../www/command-line-options.html#dispose–dispose  
../www/command-line-options.html#dither–dither  
../www/command-line-options.html#endian–endian  
../www/command-line-options.html#encoding–encoding  
../www/command-line-options.html#extract–extract  
../www/command-line-options.html#family–family  
../www/command-line-options.html#fill–fill  
../www/command-line-options.html#filter–filter  
../www/command-line-options.html#font–font  
../www/command-line-options.html#format–format  
../www/command-line-options.html#fuzz–fuzz  
../www/command-line-options.html#gravity–gravity  
../www/command-line-options.html#interlace–interlace  
../www/command-line-options.html#label–label  
../www/command-line-options.html#limit–limit  
../www/command-line-options.html#log–log  
../www/command-line-options.html#loop–loop  
../www/command-line-options.html#mask–mask  
../www/command-line-options.html#matte–matte  
../www/command-line-options.html#mattecolor–mattecolor  
../www/command-line-options.html#monitor–monitor  
../www/command-line-options.html#monochrome–monochrome  
../www/command-line-options.html#orient–orient  
../www/command-line-options.html#page–page  
../www/command-line-options.html#pointsize–pointsize  
../www/command-line-options.html#preview–preview  
../www/command-line-options.html#quality–quality  
../www/command-line-options.html#quiet–quiet  
../www/command-line-options.html#region–region  
../www/command-line-options.html#render–render  
../www/command-line-options.html#sampling-factor–sampling-factor  
../www/command-line-options.html#size–size  
../www/command-line-options.html#stroke–stroke  
../www/command-line-options.html#strokewidth–strokewidth  
../www/command-line-options.html#style–style  
../www/command-line-options.html#texture–texture  
../www/command-line-options.html#tile–tile  
../www/command-line-options.html#transparent–transparent  
../www/command-line-options.html#treedepth–treedepth  
../www/command-line-options.html#type–type  
../www/command-line-options.html#undercolor–undercolor  
../www/command-line-options.html#units–units  
../www/command-line-options.html#verbose–verbose  
../www/command-line-options.html#weight–weight  In this example, –channel applies to each of the images since as we mentioned, settings persist:
  convert -channel RGB wand.png wizard.png images.png
  
Image Operator
An image operator differs from a setting in that it affects the image immediately as it appears on the command line.  An operator is any ../www/command-line-options.htmlcommand line option  not listed as a #settingimage setting  or #sequenceimage sequence operator .  Unlike an image setting, which persists until the command line terminates, an operator is applied to an image and forgotten.
../www/command-line-options.html#affine–affine  
../www/command-line-options.html#annotate–annotate  
../www/command-line-options.html#bias–bias  
../www/command-line-options.html#black-threshold–black-threshold  
../www/command-line-options.html#blue-primary–blue-primary  
../www/command-line-options.html#blur–blur  
../www/command-line-options.html#border–border  
../www/command-line-options.html#charcoal–charcoal  
../www/command-line-options.html#chop–chop  
../www/command-line-options.html#colorize–colorize  
../www/command-line-options.html#compose–compose  
../www/command-line-options.html#contrast–contrast  
../www/command-line-options.html#convolve–convolve  
../www/command-line-options.html#crop–crop  
../www/command-line-options.html#cycle–cycle  
../www/command-line-options.html#despeckle–despeckle  
../www/command-line-options.html#draw–draw  
../www/command-line-options.html#edge–edge  
../www/command-line-options.html#emboss–emboss  
../www/command-line-options.html#enhance–enhance  
../www/command-line-options.html#equalize–equalize  
../www/command-line-options.html#evaluate–evaluate  
../www/command-line-options.html#extent–extent  
../www/command-line-options.html#flip–flip  
../www/command-line-options.html#flop–flop  
../www/command-line-options.html#floodfill–floodfill  
../www/command-line-options.html#frame–frame  
../www/command-line-options.html#gamma–gamma  
../www/command-line-options.html#gaussian–gaussian  
../www/command-line-options.html#geometry–geometry  
../www/command-line-options.html#green-primary–green-primary  
../www/command-line-options.html#implode–implode  
../www/command-line-options.html#intent–intent  
../www/command-line-options.html#lat–lat  
../www/command-line-options.html#level–level  
../www/command-line-options.html#linewidth–linewidth  
../www/command-line-options.html#map–map  
../www/command-line-options.html#mask–mask  
../www/command-line-options.html#median–median  
../www/command-line-options.html#modulate–modulate  
../www/command-line-options.html#negate–negate  
../www/command-line-options.html#noise–noise  
../www/command-line-options.html#normalize–normalize  
../www/command-line-options.html#opaque–opaque  
../www/command-line-options.html#ordered-dither–ordered-dither  
../www/command-line-options.html#paint–paint  
../www/command-line-options.html#pen–pen  
../www/command-line-options.html#posterize–posterize  
../www/command-line-options.html#raise–raise  
../www/command-line-options.html#profile–profile  
../www/command-line-options.html#quiet–quiet  
../www/command-line-options.html#radial-blur–radial-blur  
../www/command-line-options.html#raise–raise  
../www/command-line-options.html#random-threshold–random-threshold  
../www/command-line-options.html#red-primary–red-primary  
../www/command-line-options.html#resample–resample  
../www/command-line-options.html#roll–roll  
../www/command-line-options.html#rotate–rotate  
../www/command-line-options.html#sample–sample  
../www/command-line-options.html#scale–scale  
../www/command-line-options.html#separate–separate  
../www/command-line-options.html#sepia-tone–sepia-tone  
../www/command-line-options.html#segment–segment  
../www/command-line-options.html#shade–shade  
../www/command-line-options.html#shadow–shadow  
../www/command-line-options.html#sharpen–sharpen  
../www/command-line-options.html#shave–shave  
../www/command-line-options.html#shear–shear  
../www/command-line-options.html#sigmoidal-contrast–sigmoidal-contrast  
../www/command-line-options.html#solarize–solarize  
../www/command-line-options.html#splice–splice  
../www/command-line-options.html#spread–spread  
../www/command-line-options.html#stretch–stretch  
../www/command-line-options.html#strip–strip  
../www/command-line-options.html#support–support  
../www/command-line-options.html#swirl–swirl  
../www/command-line-options.html#threshold–threshold  
../www/command-line-options.html#thumbnail–thumbnail  
../www/command-line-options.html#tint–tint  
../www/command-line-options.html#transform–transform  
../www/command-line-options.html#trim–trim  
../www/command-line-options.html#unsharp–unsharp  
../www/command-line-options.html#version–version  
../www/command-line-options.html#virtual-pixel–virtual-pixel  
../www/command-line-options.html#wave–wave  
../www/command-line-options.html#white-point–white-point  
../www/command-line-options.html#white-threshold–white-threshold In this example, –negate negates the wand image but not the wizard:
  convert wand.png -negate wizard.png images.png
  
Image Sequence Operator
An image sequence operator differs from a setting in that it affects an image sequence immediately as it appears on the command line.  Choose from these image sequence operators:
../www/command-line-options.html#append–append  
../www/command-line-options.html#average–average  
../www/command-line-options.html#coalesce–coalesce  
../www/command-line-options.html#combine–combine  
../www/command-line-options.html#composite–composite  
../www/command-line-options.html#crop–crop  
../www/command-line-options.html#desconstruct–deconstruct  
../www/command-line-options.html#delete–delete  
../www/command-line-options.html#flatten–flatten  
../www/command-line-options.html#fx–fx  
../www/command-line-options.html#insert–insert  
../www/command-line-options.html#map–map  
../www/command-line-options.html#morph–morph  
../www/command-line-options.html#mosaic–mosaic  
../www/command-line-options.html#process–process  
../www/command-line-options.html#scene–scene  
../www/command-line-options.html#swap–swap  
../www/command-line-options.html#write–write   
Image Stack
In school, your teacher probably permitted you to work on problems on a scrap of paper and then copy the results to your test paper.  An image stack is similiar.  It permits you to work on an image or image sequence in isolation and then introduce the results back into the command line.  The image stack is delineated with parenthesis.  Image operators only affect images in the current stack.  For example, we can limit the image rotation to just the wizard image like this:
  convert wand.gif \( wizard.gif -rotate 30 \) +append images.gif
Notice the parenthesis are escaped.  That is there are preceded by a backslash.  This is required under Unix since parenthesis are special shell characters.  The backslash tells the shell not to interpret these characters and pass them to the ImageMagick command line.
In addition to the image operators already discussed, these image operators are most useful when processing images in an image stack:
../www/command-line-options.html#clone–clone  
../www/command-line-options.html#delete–delete  
../www/command-line-options.html#insert–insert  
../www/command-line-options.html#swap–swap The arguments to these operators are indexes into the image sequence by number, starting with zero, for the first image, and so on. However if you give a negative index, the images are indexed from the end (last image added). That is a index of -1 is the last image in the current image sequence, -2 for the second last and so on.
  
Output Filename
ImageMagick extends the concept of an output filename to include: 1) an explicit image format; 2) writing to standard out; and 3) specifying a TIFF tile size.  Each of these extensions are explained in the next few paragraphs.
Explicit Image Format  
Images can be stored in a mryiad of image formats including the better known JPEG, PNG, TIFF and others.  ImageMagick must know the desired format of the image before it is written.  ImageMagick leverages the filename extension to determine the format.  For example, image.jpg tells ImageMagick to write the image in the JPEG format.  In some cases the filename does not identify the image format.  In these cases, the image is written in the format it was originally read unless an explicit image format is specified.  For example, suppose we want to write our image to a filename of image in the raw red, green, and blue intensity format:  convert image.jpg rgb:image
Standard Out  
Unix permits the output of one command to be piped to another.  ImageMagick permits piping one command to another with a filename of –.  In this example we pipe the output of convert to the display program:  convert logo: gif:- | display gif:-
  
Here the explicit format is optional.  The GIF image format has a signiture that uniquely identifies it so ImageMagick can readily recognize the format as GIF.TIFF Tile Size  
You can specify the TIFF tile size by appending the image filename with the tile width and height enclosed in brackets.  Here, we write image tiles that are 64 pixels wide and 64 pixels high with this command:  convert wizard.png wizard.tif[64x64]
  
Unix shells generally interpret backets so we should enclose the filename in quotes:  convert wizard.png 'wizard.tif[64x64]'
      

      
 
    

  

  

  

    
http://redux.imagemagick.org/discussion-serverDiscourse Server  |
    
../www/mailing-list.htmlMailing Lists  |
    
http://redux.imagemagick.org/galleryImage Gallery  |
    
http://studio.webbyland.com/MagickStudio/scripts/MagickStudio.cgiImageMagick Studio 
  

  

    
© 1999-2005 ImageMagick Studio LLC
  

  



