Vicente González Ruiz
September 12, 2016
Contents
Chapter 1
Introduction
- ImageMagick® is a software suite to create, edit, compose, or convert
bitmap (raster) and vector images.
- It runs on Linux, Windows, Mac Os X, iOS, Android OS, and others.
- The functionality of ImageMagick is typically utilized from the command
line, although you can use the features from programs written in your
favorite language (Perl, C, Ruby and PHP).
- ImageMagick is free software distributed under The Apache 2.0 license.
- There is a forum where you can answer your questions.
1.2 Installed version
1.4 Delegates
- Depending on how ImageMagick was configured, there is a collection of delegate
programs (for example, to create a MPEG file ImageMagick uses FFMPEG).
1.5 (Local) Help
- All ImageMagick commands has man page:
- Each ImageMagick command has a buit-in help:
1.6 Debugging
- Standard debug:
wget http://www.hpca.ual.es/~vruiz/images/lena.png .
convert lena.png lena.jpg
- No debug:
convert +debug lena.png lena.jpg
- Debug:
convert
−debug lena.png lena.jpg
- More debug:
convert
−verbose lena.png lena.jpg
- Progress information:
convert
−monitor lena.png lena.png
1.7 Commands
- animage: plays an image sequence.
- compare: compares images.
- composite: overlaps images.
- conjure: performs custom image processing tasks from a script written in
the Magick Scripting Language (MSL).
- convert: resizes, blurs, crops, despeckles, dithers, draws on, flips, joins,
re-samples, and much more.
- display: shows an image.
- identify: describes the format and characteristics of one or more images.
- import: captures images from the screen.
- mogrify: identical to convert, but overwrites the original image file.
- montage: composites images by combining others.
- stream: extracts regions directly from disk to disk (without loading the
image in the memory).
Chapter 2
Displaying
- Describe the format and characteristics of one or more image files.
# Basic information about the built
−in "rose" image:
identify rose:
# Idem for lena.png:
identify lena.png
# Extremely basic:
identify
−ping rose:
# Get extra information:
identify
−verbose rose:
- Display an image or image sequence on any X server.
# Create an image with the inline image "rose".
convert rose: rose.png
# Display de image using an independent window.
display rose.png &
# Using the root window.
display
−size 1280x1024
−window root rose.png &
# Built a preview in a visual image directory.
wget http://www.hpca.ual.es/~vruiz/videos/tempete_352x288x30x420x260.avi
convert tempete_352x288x30x420x260.avi tempete%03d.png
display ’vid:
∗.png’ &
# Using pipes:
convert logo: gif:
− | display
− &
# ^ ^ ^
# | | |
# stdout pipe stdin
2.4 Using file
# Create the image "rose.png":
convert rose: rose.png
# Get information:
file rose.png
Chapter 3
Capturing
- 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.
- Capture a window:
- Capture a region:
- Capture the entire screen:
import
−window root screen.png
Chapter 4
Creating & converting
- Convert between image formats as well as resize an image, blur, crop,
despeckle, dither, draw on, flip, join, re-sample, and much more.
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:white
−snow4 \
−draw ’roundrectangle 16, 5, 304, 85 20,40’ +tile
−fill snow \
−draw ’roundrectangle 264, 5, 304, 85 20,40’
−tile gradient:chartreuse
−green \
−draw ’roundrectangle 16, 5, 180, 85 20,40’
−tile gradient:chartreuse1
−chartreuse3 \
−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
- 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 &
- Using a file with the names of the still images:
cat << EOF > example_using_references.sh
#!/bin/bash
set
−x
# 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[0
−3]’ 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/Sumatran
−Tiger
−Hero.jpg?1345559303
wget http://4.bp.blogspot.com/
−OHVlacYzSlU/TZBinlfNXzI/AAAAAAAAEFI/tqaeTB2wfTA/s1600/Clara%20Lago%20Pictures.jpg
convert
−morph 50 Sumatran
−Tiger
−Hero.jpg\?1345559303 Clara\ Lago\ Pictures.jpg output.mng
4.6 Watermarking
- 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
- 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, 8
−bit/color RGB, non
−interlaced
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
- 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.
montage
−label %f
−frame 10
−shadow
−tile 4
∗.jpg output.jpg
# ^ ^ ^ ^
# | | | |
# | | | number of images per row
# | | create a shadow for each image
# | use a frame os 10 pixels
# filename
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
−sampling
−factor 2x1 input.png output.png
7.3 Changing the quality
- In JPEG:
convert
−quality 15% input.png output.jpg
- 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 8
−bit 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
- The contrast is the difference in luminance to make and object distinguishable.
# Increasing:
convert
−constrast input.png output.png
# Decreasing:
convert +constrast input.png output.png
7.9 Dithering
- Reduces the number of colors.
# Using 2 colors:
convert
−dither
−monochrome input.png output.png
# Using 4 colors:
convert
−dither
−colors 4 input.png output.png
7.10 Equalizing
- Increases the dynamic range of the colors of the image.
convert
−equalize input.png output.png
7.11 Normalizing
- Increases the dynamic range of the colors of the image.
convert
−normalize input.png output.png
7.12 Bluring
- Low pass filtering:
convert
−blur 10 input.png output.png
# ^
# |
# radius
conver
−blur 7x3 input.opng output.png
# ^
# |
# size of the convolutional mask
7.13 The charcoal effect
- High pass filtering:
convert
−charcoal 2 input.png output.png
# ^
# |
# thicknes of the boundaries
7.14 The impode effect
- A sink effect:
convert
−implode 2 input.png output.png
# ^
# |
# factor
7.15 Denoising
- Removes noise:
convert
−noise 3 input.png output.png
# ^
# |
# radii
7.16 The paint effect
- Simulates oil painting:
convert
−paint 3 input.png output.png
# ^
# |
# radii
7.17 The radial-blur effect
- Simulates oil painting:
convert
−radial
−blur 30 input.png output.png
# ^
# |
# angle
7.18 Sementing
- Automatic image segmentation:
convert
−segment 1.75x2.0 input.png output.png
# ^ ^
# | |
# | smoothing
# clustering
7.19 The sepia-tone effect
- A vintage effect:
convert
−sepia
−tone 75% input.png output.png
# ^
# |
# percentage
7.20 The shade effect
- Produces shades:
convert
−shade 0x10 input.png output.png
# ^ ^
# | |
# | elevation of the source of light
# azimuth
7.21 Sharpenning
- Using a Gaussian filtering to enhance the color boundaries:
convert
−sharpen 3x6 input.png output.png
# ^ ^
# | |
# | standard deviation
# radii
7.22 Negating
- A negative effect:
convert
−negate input.png output.png
7.23 The solarize effect
- Another negative effect:
convert
−solarize 30 input.png output.png
# ^
# |
# factor
7.24 The spread effect
- Swaps pixels randomly:
convert
−spread 7 input.png output.png
# ^
# |
# radii
7.25 The wave effect
- Shakes the image:
convert
−wave 10x90 input.png output.png
# ^ ^
# | |
# | frequency
# amplitude
Chapter 8
Editing
8.1 Annotating
- Put text inside images.
convert
−annotate 0x0+30+40
−stroke blue
−fill red ‘‘text’’ input.png output.png
# ^ ^
# | |
# | Y offset
# X offset
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
- Absolute size:
convert
−resize 352x288 input.jpg output.jpg
- Maximum size (not larger than) and conserving the width/height ratio:
convert
−resize 352x288< input.jpg output.jpg
- Minimum size (not smaller than) and conserving the width/height
ratio:
convert
−resize 352x288> input.jpg output.jpg
- Percentage change:
convert
−resize 25% input.jpg output.jpg
- Maximun number of pixels:
convert
−resize 25000@ input.jpg output.jpg
- Sampling (changes both, the resolution and the image size):
convert
−sample 250% input.jpg output.jpg
- Resampling (in dots per inch). It changes the resolution, but not the
size:
convert
−resample 150x150 input.jpg output.jpg
- Using a faster (but unaccurate) algorithm:
convert
−scale 200% input.jpg output.jpg
- 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
- Put the input image at an angle.
convert
−shear 45x10 input.png output.png
# ^ ^
# | |
# | vertical shearing
# horizontal
8.8 Averaging
convert
−average
∗.png output.png
8.9 Cropping
- 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
- Remove a border:
convert
−shave 10x10 input.jpg output.jpg
- Remove the constant border:
convert
−trim input.jpg output.jpg
- Remove the similar border:
convert
−fuzz 10% input.jpg output.jpg
8.10 Chopping
- Removes columns and rows (both, at the same time) of an image.
convert
−chop 500x600+700+800 input.png output.png
# ^ ^ ^ ^
# | | | |
# | | | Y offset
# | | X offset
# | height of the removed region
# width of the removed region
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