ImageMagick

Vicente González Ruiz

September 12, 2016

Contents

1 Introduction
 1.1 About ImageMagick
 1.2 Installed version
 1.3 Listing the supported image formats
 1.4 Delegates
 1.5 (Local) Help
 1.6 Debugging
 1.7 Commands
2 Displaying
 2.1 Using identify
 2.2 Using display
 2.3 Using animate
 2.4 Using file
3 Capturing
4 Creating & converting
 4.1 Using built-in images
 4.2 Creating animated images
 4.3 Extracting images from an animated image or video
 4.4 Disolving
 4.5 Morphing
 4.6 Watermarking
 4.7 Removing and putting on headers
5 Comparing
 5.1 Compare two images
6 Composing
 6.1 Overlaping images
 6.2 Montaging
7 Processing
 7.1 Reducing the number of colors
 7.2 Chroma subsampling
 7.3 Changing the quality
 7.4 Gamma correction
 7.5 Transparency
 7.6 Scale
 7.7 Crop
 7.8 Manipulating contrast
 7.9 Dithering
 7.10 Equalizing
 7.11 Normalizing
 7.12 Bluring
 7.13 The charcoal effect
 7.14 The impode effect
 7.15 Denoising
 7.16 The paint effect
 7.17 The radial-blur effect
 7.18 Sementing
 7.19 The sepia-tone effect
 7.20 The shade effect
 7.21 Sharpenning
 7.22 Negating
 7.23 The solarize effect
 7.24 The spread effect
 7.25 The wave effect
8 Editing
 8.1 Annotating
 8.2 Removing metadata
 8.3 Change metadata
 8.4 Scaling
 8.5 Rotating
 8.6 Flipping
 8.7 Shearing
 8.8 Averaging
 8.9 Cropping
 8.10 Chopping
 8.11 Adding images
 8.12 Inserting images
 8.13 Deleting images
 8.14 Swapping images
 8.15 Appending

Chapter 1
Introduction

1.1 About ImageMagick

y = x2 (1.1)

1.2 Installed version

convert version

1.3 Listing the supported image formats

identify list format

1.4 Delegates

1.5 (Local) Help

1.6 Debugging

1.7 Commands

  1. animage: plays an image sequence.
  2. compare: compares images.
  3. composite: overlaps images.
  4. conjure: performs custom image processing tasks from a script written in the Magick Scripting Language (MSL).
  5. convert: resizes, blurs, crops, despeckles, dithers, draws on, flips, joins, re-samples, and much more.
  6. display: shows an image.
  7. identify: describes the format and characteristics of one or more images.
  8. import: captures images from the screen.
  9. mogrify: identical to convert, but overwrites the original image file.
  10. montage: composites images by combining others.
  11. stream: extracts regions directly from disk to disk (without loading the image in the memory).

Chapter 2
Displaying

2.1 Using identify

2.2 Using display

2.3 Using animate

2.4 Using file

# Create the image "rose.png": 
convert rose: rose.png 
 
# Get information: 
file rose.png

Chapter 3
Capturing

  1. Capture a window:
    import window.png
  2. Capture a region:
    import frame region.png
  3. Capture the entire screen:
    import window root screen.png

Chapter 4
Creating & converting

4.1 Using built-in images

# Create a image with a checkerboard. 
convert size 640x480 pattern:checkerboard checkerboard.png 
 
# Show percent completion of a task as a shaded cylinder. 
convert size 320x90 canvas:none stroke snow4 size 1x90 tile gradient:whitesnow4 \ 
  draw ’roundrectangle 16, 5, 304, 85 20,40’ +tile fill snow \ 
  draw ’roundrectangle 264, 5, 304, 85  20,40’ tile gradient:chartreusegreen \ 
  draw ’roundrectangle 16,  5, 180, 85  20,40’ tile gradient:chartreuse1chartreuse3 \ 
  draw ’roundrectangle 140, 5, 180, 85  20,40’ +tile fill none \ 
  draw ’roundrectangle 264, 5, 304, 85 20,40’ strokewidth 2 \ 
  draw ’roundrectangle 16, 5, 304, 85 20,40’ \( +clone background snow4 \ 
  shadow 80x3+3+3 \) +swap background none layers merge \( +size font Helvetica \ 
  pointsize 90 strokewidth 1 fill red label:’50 %’ trim +repage \( +clone \ 
  background firebrick3 shadow 80x3+3+3 \) +swap background none layers merge \) \ 
  insert 0 gravity center append background white gravity center extent 320x200 \ 
  png: | display 

4.2 Creating animated images

  1. Using a globbing parameter:
    # Create a sequence of PNG images. 
    wget http://www.hpca.ual.es/~vruiz/videos/tempete_352x288x30x420x260.avi 
    convert tempete_352x288x30x420x260.avi tempete%03d.png 
     
    # Create a GIF animation with a sequence of PNG images. 
    convert loop 0 delay 100 tempete.png tempete_animated.gif 
    #            ^          ^         ^ 
    #            |          |         | 
    #            |          | filename globbing 
    #            |        delay between images 
    #         Loop forever 
     
    firefox tempete_animated.gif &
  2. Using a file with the names of the still images:
    cat << EOF > example_using_references.sh 
    #!/bin/bash 
     
    set 
     
    # Empty file. 
    echo n "" > references.txt 
     
    # Create the "references.txt" file. 
    for (( i=0; i<100; i++ )) 
    do 
      index_i=\‘printf "%02d" \$i\‘ # Be carefully with the ’\‘’! 
      filename=checker\$index_i.png 
      convert size 256x256 pattern:checkerboard’[’256x256+\$i+\$i’]’ \$filename 
      echo \$filename >> references.txt 
    done 
     
    # Create the movie using the references file. 
    convert @references.txt movie.gif 
     
    set +x 
    EOF 
     
    chmod +x example_using_references.sh 
    ./example_using_references.sh

4.3 Extracting images from an animated image or video

convert tempete_352x288x30x420x260.avi tempete.gif 
 
# Extracting the first image of an animated GIF. 
convert ’tempete.gif[0]’ tempete.png 
display tempete.png 
 
# Extracting a range of images. 
convert ’tempete.gif[03]’ tempete.mng 
display tempete.mng 
 
# Extracting images out of order. 
convert ’tempete.gif[3,2,4]’ tempete.mng 
display tempete.mng

4.4 Disolving

composite disolve 50% source1.jpg source2.png creation.tif

4.5 Morphing

wget http://assets.worldwildlife.org/photos/2090/images/hero_full/SumatranTigerHero.jpg?1345559303 
wget http://4.bp.blogspot.com/OHVlacYzSlU/TZBinlfNXzI/AAAAAAAAEFI/tqaeTB2wfTA/s1600/Clara%20Lago%20Pictures.jpg 
convert morph 50 SumatranTigerHero.jpg\?1345559303 Clara\ Lago\ Pictures.jpg output.mng

4.6 Watermarking

  1. Visible:
    # No offset: 
    composite watermark 50% mark.png foreground.jpg output.png 
     
    # Centering the mark: 
    composite watermarck 40% gravity center marck.jpg foreground.jpg output.jpg
  2. Invisible:
    # Hide ‘‘hidden_mark.png’’ inside of ‘‘foreground.jpg’’: 
    composite stegano 101 hidden_mark.png foreground.jpg output.jpg 
    #                   ^ 
    #                   | 
    #       offset of the hidden mark 
     
    # Extract the hidden image: 
    display 200x100+101 stegano:output.png 
    #          ^     ^ 
    #          |     | 
    #          | offset of the hidden mark 
    #  size of the hidden marck

4.7 Removing and putting on headers

file tempete000.png 
# tempete000.png: PNG image data, 352 x 288, 8bit/color RGB, noninterlaced
convert tempete000.png rgb:tempete_352x288_8bpp_rgb.raw 
#                      ^^^ 
#    We specify an explicit output image format.

 # See Section 4.2 to create tempete000.png.

convert size 352x288 depth 8 rgb:tempete.rgb tempete.gif 
#       ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
 
# "raw_image" is an input collection of 640x480 RGB samples without any header: 
convert size 640x480 depth 8 rgb:raw_image image.png 
#                              ^^^

Chapter 5
Comparing

5.1 Compare two images

compare image1.png image2.png difference.png

Chapter 6
Composing

6.1 Overlaping images

composite first.png second.png composite.png

6.2 Montaging

Chapter 7
Processing

7.1 Reducing the number of colors

convert colors 256 input.tif output.png 
# or 
convert depth 8 input.tif output.png

7.2 Chroma subsampling

# Selects YUV 4:2:2 chroma subsampling: 
convert samplingfactor 2x1 input.png output.png

7.3 Changing the quality

  1. In JPEG:
    convert quality 15% input.png output.jpg
  2. In JPEG2000:
    convert quality 15% input.png define "jp2:rate=1.0" output.jp2

7.4 Gamma correction

conver gamma 1.5,1.6,0.9 input.png output.png

7.5 Transparency

# Pure red will be transparent: 
convert transparent red input.gif output.gif

7.6 Scale

Inline (while reading) multiple image processing:

# Creates a 120x120 PNG thumbnail of each input image in the current directory. Each 
# image is processed as follows: read > resize > write. 
convert ’tempete.png[120x120]’ tempete_thumbnail%03d.png 
animate tempete_thumbnail.png

7.7 Crop

identify tempete000.png 
# tempete000.png PNG 352x288 352x288+0+0 8bit DirectClass 200KB 0.000u 0:00.000 
#                                    ^ ^ 
#     These offsets are important because should be added to "xo" and "yo"! 
 
convert ’tempete000.png[100x200+50+50]’  | display  
#                       ^^^ ^^^ ^^ ^^ 
#                       col row xo yo 
# col = column, row = row, xo = x offset, yo = y offset. 
 
# The same as previous example, but using (inline, while reading) cropping instead resizing. 
convert ’.jpg[120x120+10+5]’ thumbnail%03d.png

7.8 Manipulating contrast

7.9 Dithering

7.10 Equalizing

7.11 Normalizing

7.12 Bluring

7.13 The charcoal effect

7.14 The impode effect

7.15 Denoising

7.16 The paint effect

7.17 The radial-blur effect

7.18 Sementing

7.19 The sepia-tone effect

7.20 The shade effect

7.21 Sharpenning

7.22 Negating

7.23 The solarize effect

7.24 The spread effect

7.25 The wave effect

Chapter 8
Editing

8.1 Annotating

8.2 Removing metadata

identify verbose input.jpg 
convert strip input.jpg output.jpg 
identify verbose output.jpg

8.3 Change metadata

convert comment ‘‘This image was created by ...’’ input.jpg output.jpg 
convert density 150x150 units PixelsPerInch input.jpg output.jpg

8.4 Scaling

  1. Absolute size:
    convert resize 352x288 input.jpg output.jpg
  2. Maximum size (not larger than) and conserving the width/height ratio:
    convert resize 352x288< input.jpg output.jpg
  3. Minimum size (not smaller than) and conserving the width/height ratio:
    convert resize 352x288> input.jpg output.jpg
  4. Percentage change:
    convert resize 25% input.jpg output.jpg
  5. Maximun number of pixels:
    convert resize 25000@ input.jpg output.jpg
  6. Sampling (changes both, the resolution and the image size):
    convert sample 250% input.jpg output.jpg
  7. Resampling (in dots per inch). It changes the resolution, but not the size:
    convert resample 150x150 input.jpg output.jpg
  8. Using a faster (but unaccurate) algorithm:
    convert scale 200% input.jpg output.jpg
  9. Thumbnails:
    # Only one image: 
    convert thumbnail 10% input.jpg output.jpg
    # A group of images (this example does not overwrites the original images): 
    mogrify format png thumbnail 15% .jpg

8.5 Rotating

convert rotate 75 input.png output.png

8.6 Flipping

# Vertically: 
convert flip input.png output.png 
 
# Horizontaally: 
convert flop input.png output.png

8.7 Shearing

8.8 Averaging

convert average .png output.png

8.9 Cropping

  1. Extract a subregion:
    convert crop 999x768+100+200 input.png output.png 
    #              ^   ^   ^   ^ 
    #              |   |   |   | 
    #              |   |   | Y offset 
    #              |   | X offset 
    #              | height of the extracted image 
    #            width of the extracted image
  2. Remove a border:
    convert shave 10x10 input.jpg output.jpg
  3. Remove the constant border:
    convert trim input.jpg output.jpg
  4. Remove the similar border:
    convert fuzz 10% input.jpg output.jpg

8.10 Chopping

8.11 Adding images

convert image1.jpg image2.png image3.tif output.pdf

8.12 Inserting images

# Inserts ‘‘image.png’’ as the 3rd image: 
convert insert 3 image.png input.mng output.gif

8.13 Deleting images

# Deletes the 3rd, 4th and 10th images: 
convert delete 3,4,10 input.mng output.gif

8.14 Swapping images

# Swaps the 3rd, 4th images: 
convert delete 3,4 input.mng output.gif

8.15 Appending

convert top.png bottom.png append result.png