Found via MarkPilgrim's DiveIntoMark. Looks very useful, archived here for posterity.
See also: ImageManipulation
This file contains...
Hints and tips specific to Imagemagick
NOTE: General hints which can be handled by both imagemagick and other
filters can be found in "algorithms.hints" of this same directory.
If you like to contribute a suggestion of technique, mail it to me at
Anthony Thyssen <anthony@cit.gu.edu.au>
From a Developer...
ImageMagick is a robust general solution to a number of image processing
problems. We traded off speed for robustness and image quality.
-------------------------------------------------------------------------------
What formats does IM know..
convert -list
This fails for version < 5.4.9 and only lists options (-type isn't listed!)
However the font list option works!
convert -list type
-------------------------------------------------------------------------------
Basic Image information
Basic summery
identify test.png
Lots more info
identify verbose test.png
In version beta/5.5.2, even more...
identify -debug coders -log %e test.png
-------------------------------------------------------------------------------
Builtin Images
logo: ImageMagick Logo Image
rose: A rose image
netscape: The netscape colormap
granite: a classic tile pattern
Other image generators (not actual image formats)
The following need a "-size" option specified
plasma: Plasma fractal background
xc:color Solid color image
gradient:color1-color2 gradent map vertically across image
ASIDE: broken in v5.4.9
tile:tile_image_file fill image with given tile pattern
(try tile:granite:)
label:string generate image of string in current font
Special destination...
print: If used at a final target, image will be sent to the printer
as postscript. Eg: convert logo: print:
Patterns (v5.5.7 and above) EG: pattern:bricks
See bottom of http://www.imagemagick.org/www/formats.html
-------------------------------------------------------------------------------
Gradients
When I need a gradient, I generate a 2x2 image in PPM format and then
use -geometry to expand it to the size I need.
echo "P3 2 2 255\n0 220 240 0 140 150 0 140 150 0 80 80" | \
convert -geometry 512x512 - miff:- | display
-------------------------------------------------------------------------------
Color Reduction
If you are color reducing an image, say for example from JPEG to GIF, you may
find reds/greens/blue showing up in areas of mostly uniform grays. To stop
this, use the YUV colorspace:
convert -colorspace YUV -colors 256 image.jpg image.gif
-------------------------------------------------------------------------------
Set background color as being transparent
Assuming the top left pixel is the color to be made transparent use..
convert -draw 'matte 0,0 replace' input.img output.img
This will also set any 'holes' in the image of the background color
as also being transparent. If you only want the outside of the image
leaving any 'holes' of the same colour alone use
convert -draw 'matte 0,0 floodfill' input.img output.img
ASIDE: The manpage on the 'draw' option is obsure and could be more formal
with examples to explain the various drawing options.
See below in "outline font drawing".
-------------------------------------------------------------------------------
Replace one color with another
convert -fill blue -opaque white white.png blue.png
or convert a black and white to a blue print (blue on black)
convert -fill blue -opaque black \
-fill black -opaque white \
bw_plan.gif blueprint.gif
To also set certain colors as transparent use
# tc = transparent color c1 c2 c3 = colors to make transparent
convert in.gif -matte -fill tc -opaque c1 -opaque c2 -opaque c3 \
-transparent tc out.gif
-------------------------------------------------------------------------------
Thumbnail Generation (for web pages)
I store images in jpg format, then use gif format for the images thumbnail.
I then have a simple perl script to generate a html page of thumbnail links
to the full sized jpeg images. (Mail me if you are interested in this).
Convert ONE jpg images to gif thumbnails 90 pixels high (any reasonable width)
convert -geometry 200x90 dscn9568.jpg dscn9568.gif
Convert ALL jpg images to gif thumbnails
mogrify -format gif -geometry 200x90 *.jpg
NOTE: this will blindly create thumnails. Better thumbnails can be created
by manually cropping the "important" part of the image, shrinking and resaving
as a gif. As this will overwrite any existing, posibly hand generated
thumbnails, extreme caution is advised.
Alturnatives...
XV generates its own thumbnails in the .xvpics subdirectory, using its own
format. (ignore the suffix of the image in .xvpics sub-directory). These XV
thumnails however limited to 80x60 pixels os are a little on the "small" size.
IM understands the XV formats, so you can re-generate thumbnails from the XV
thumenails, fast. So to convert those "jpg" XV thumbnails into "gif"
thumbnails use...
xv & # then Ctrl-V to run the "Visual Schnauzer"
# generate thumbs with the "Update" button
rm .xvpics/*.gif # delete XV thumbs of existing "gif" thumbnails
mogrify -format gif .xvpics/*.jpg
mv .xvpics/*.gif . # move the new "gif" thumbnails to original dir
If you are sick of the small size, particularly with larger modern displays
see my XV modification notes...
http://www.sct.gu.edu.au/~anthony/info/graphics/xv_mods.hints
I myself like to use a large 120x90 pixel size thumnail within XV.
But then for WWW thumbnails I prefer the manual approach (see NOTE above)
-------------------------------------------------------------------------------
Extracting the transparency mask
convert some.gif some.matte
convert some.matte some_mask.xbm
will extract the matte (or transparency) channel and save it as a X
bitmap.
The latest Imagemagick v4.0 also allows you to extact with
convert -layer matte some.gif image.xbm
To install the transparency (matte)
convert -compose ReplaceMatte full-color.png bitmap.gif image.png
NOTE the matte channel can be partially transparent.
-------------------------------------------------------------------------------
Dither just the transparency (alpha) channel
Do this with to commands...
convert -channel Opacity -monochrome -dither file.tiff opacity.pgm
composite -compose Copy file.tiff file.tiff opacity.pgm output.tiff
The alpha channel will probably still be 8-bit but it will only contain
the fully opaque and fully transparent values. Note: "Opacity" may be "Matte"
on earlier IM convert commands.
-------------------------------------------------------------------------------
Convert grey shades to transparency
Create a blank transparent image of the correct dimensions.
Use "composite" to composite your image onto it along with
a negated copy of your image used as the mask.
convert -size 640x468 xc:transparent -matte blank.png
convert -negate image.png mask.png
composite image.png blank.png mask.png result.png
Glenn Randers-Pehrson
I'm just wondering if it might be a good idea to just use xc:black instead of
the original image. That way the actual text color (black) instead of grey is
averaged with the background via the transparency.
Jeff Spirko
-------------------------------------------------------------------------------
Concatanation of images
Join all the images into rows and columns without gaps....
This is usefull to allow creation of numbers and text from individual
character images, Simular to using real fonts but with full color.
You can now just use -append (top down) or +append (left to rigth)
This will also preserve the transparency of the image.
convert +append g.gif r.gif e.gif g.gif greg.gif
If you don't mind lusing the transparency you can also use...
montage -mode Concatenate -tile 999x1 -compose in \
g.gif r.gif e.gif g.gif greg.gif
OR for very very old versions of ImageMagick...
montage +frame +shadow +label -geometry +0+0 -tile 999x1 -compose in \
g.gif r.gif e.gif g.gif greg.gif
A "-compose in" switch added to the above was suposed to ensure that any
transparency is preserved. It use to work but now only preserves the
GIF color used for the transparency.
Hmmm "-compose Over" is suposed to make the background color
of the montage show through transparent parts of images.
WARNING: Montage picks up the frame color from the image itself. Override
with -background or whatever command line argument defines the frame color
-------------------------------------------------------------------------------
Good Image Combine'ations
NOTE: all images are found in the given path appended to the URL of
Anthony's X window Icon Library....
http://www.sct.gu.edu.au/~anthony/icons/
NOTE: "combine" was replaced by "composite", but with the image arguments
reversed.
EG: combine -compose over background.gif overlay.gif output.gif
Is now composite -compose over overlay.gif background.gif output.gif
Only the order of the images is important not the image position relative to
compose option so that last is also equivelent to either
composite overlay.gif -compose over background.gif output.gif
composite overlay.gif background.gif -compose over output.gif
Also note that to position images within images
composite uses -geometry and convert uses -page.
And -gravity affects how -geometry works, but not -page.
---
Position a image (with transparency) on top of another image.
Here a hand pointing out the small craws of the faerie dragon.
composite -compose over -geometry +31+105 \
desc/cl-32/hand_point.xpm large/dragon_faerie.xpm \
miff:- | display
or put a "sun" in the center of a scroll
composite -gravity center -compose over \
large/sunny.gif large/map.gif miff:- | display
or overlaying a 32x32 castle on a button template
composite -compose over -geometry +4+4
desc/cl-32/castle.xpm prog/template/button.xpm miff:- | display
This shows how to make a shadowy image on the map
composite -gravity center -compose bumpmap \
large/dragon_faerie.xpm large/map.gif miff:- | display
Draw image over a tiled 'bumpmap' as if image is drawn on a bumpy metal
floor. (a xbitmap, Note: imagemagick seets to like white foreground!)
Note bumpmaps seem to be converted to grey scale for this operation
composite -compose bumpmap -negate -tile prog/patterns/bumps.xbm
large/dragon_faerie.xpm miff:- | display
or
composite -compose bumpmap desc/bw-bgnd/marble.xbm \
large/dragon_faerie.xpm miff:- | display
Add a pagecurl image to lower-right corner...
NOTE: The pagecurl image was created via gimp's pagecurl filter, on a small
transparent image. The outside was then manually filled with black. An extra
mask can also be applied later to re-add transparency in the corner.
composite -gravity SouthEast pagecurl.png mermaid.jpg miff:- | display
Merge postscript image onto a postscript page.
Position image relative to the top right corner (fixed margin from edge).
composite -gravity NorthEast -geometry +40+75 \
diagram.eps -compose multiply "page.ps[0]" page.png
Add add a extra line of pixels to an image...
Say your images is 99x99 and you want 100x99:
convert -size 100x99 xc:black canvas.miff
composite -compose replace image.png canvas.miff newimage.png
Add a watermark to image...
composite -compose bumpmap -gravity southeast watermark.png \
input.jpg output.jpg
Draw an anti-aliased circle (from mailing list)
convert -size 200x200 xc:white -antialias -fill orange \
-draw "circle 100,100 100,175" miff:- | display
With a border outline
convert -size 200x200 xc:white -antialias \
-fill green -stroke orange -strokewidth 4 \
-draw "circle 100,100 100,175" miff:- | display
Complex draw commands.
You can specify complex draw commands from a file using
-draw @draw_commands
This also avoids any OS problems with things like UTF-8 unicode characters.
EG: in the file put...
encoding 'UTF-8'
text 10,90 ' unicode UTF-8 characters'
-------------------------------------------------------------------------------
Combining multiple images
There are a number of options which combine a large number of images into
a single resultant image. For Example...
convert image1 image2... -flatten output.png
These options are very useful and should not be under estimated.
All of then follow the same style. Images following the option
are merged one my one in sequence, until any other otpion is seen.
Nice, but as options are often needed to "setup" and image not useful.
The other method, shown above, is when no other input images follow.
In this can all of the input images will be used.
WARNING: watch out for multiple image formats in input (Eg: GIF animations,
multipage postscript files). If nessary, use the "[n]" suffix to select which
image from that file you want to use. Simularly use "+adjoin" to ensure the
output is not a multi-page image.
-mosaic Create a canvas and position images using -page option.
No initial background image is needed, though itcan be provided.
NOTE: I have NOT found how to specify the background color of
undefined areas of the image. Default is white.
-coalesce Merge images together, in sequence. The disposal methods will be
applied as given (EG: as provided for a gif/miff/mng animation).
A initial background image is recomened or results will be not
well defined, especially for web use.
-flatten Just layer the images on top of each other. Images wich overlap
will be hidden by later images unless transparent. Presumably
disposal methods will not be applied.
-average merge the images averaging ther values.
all images must be the same size!
-append Just stack the images, edge to edge, from top to bottom. making
one tall image. For left to right use +append instead.
This can also be done with montage "Concatenate" though that has
a lot of other side effects as well.
Options useful with the above include
-page <position> reposition the second and later images to this location
relative to the top left corner.
-geometry <size/pos> Used with -compose to size and position the next image.
-background <color> color to use for areas without an image (doesn't work?)
For example, position some small images in the middle of a larger...
The "-page" works on the "small.gif" image
convert bg.jpg -page +100+100 small1.gif \
-page +300+300 small2.gif -mosaic output.png
A single image only can be composited onto a larger image...
composite -geometry +100+50 small.gif bg.jpg -compose over output.png
See also postscript file merge above.
Don't forget you can also use compose operations in either convert -draw or
composite operations to do some very specific stuff (see previous section)
Though I haven't had much success with that.
convert bg.jpg -draw "image over 100,100 0,0 small1.gif" \
-draw "image over 300,300 0,0 small2.gif" output.png
-------------------------------------------------------------------------------
Font Display and techniques...
NOTE: Imagemagick handles ttf fonts by using the re-encoding rules built into
ghostscript. This may change if freetype is also installed into IM.
The default available system fonts can be seen with...
convert -list type
The fonts are located by IM using a "type.mgk" file which can be generated
into a personal ".magick/type.mgk" file using a script, I wrote.
See http://www.sct.gu.edu.au/~anthony/software/imagic_type_gen.pl
This means that instead of using
-font /home/anthony/lib/font/truetype/favoriate/candice.ttf
I can use a much simpler (case insensitive) font label.
-font Candice
Fonts are usally draw with anti-aliasing smoothing. If you don't want this
(say for GIF transparency) add the option +antialias to the command line.
Examples....
WARNING: -pen in IM5.4 is now -fill in IM5.5
Produce a sample image of a font in multiple sizes as a gif
convert arial.ttf arial.gif
or direct control.. (input, font, draw, output)
convert -pointsize 72 -font Candice label:Hello miff:- | display &
On to a colored background
convert -background cyan -pointsize 72 -font Candice \
label:Hello miff:- | display &
On to a transparent background
convert -background transparent -pointsize 72 -font Candice \
label:Hello miff:- | display &
To sharpen the above text drawing command add
(from Ron Savage, ron@savage.net.au on)
-stroke none
or drawn onto a background then crop the image to size
convert -size 300x100 xc:blue \
-font DoorJamb -pointsize 72 \
-draw 'text 10,75 "Test"' \
-crop 0x0 miff:- | display &
Hard Shadow (for a soft fuzzy shadow - see "Drop Shadow" below)
convert -size 400x120 xc:blue \
-font Cressdia -pointsize 72 \
-fill black -draw 'text 25,85 "Anthony"' \
-fill white -draw 'text 20,80 "Anthony"' \
-crop 0x0 miff:- | display &
Fake an outlined font from a solid font -- LOOKS GOOD
convert -size 500x120 xc:blue \
-font BrushFlash -pointsize 72 \
-fill black -draw 'text 27,87 "Anthony"' \
-draw 'text 23,87 "Anthony"' \
-draw 'text 23,83 "Anthony"' \
-draw 'text 27,83 "Anthony"' \
-fill white -draw 'text 25,85 "Anthony"' \
-crop 0x0 miff:- | display &
Same again but with a 8 point circle (for fonts with sharp points)
convert -size 500x120 xc:blue \
-font Beetlejuice -pointsize 72 \
-fill black -draw 'text 27,87 "Anthony"' \
-draw 'text 25,88 "Anthony"' \
-draw 'text 23,87 "Anthony"' \
-draw 'text 22,85 "Anthony"' \
-draw 'text 23,83 "Anthony"' \
-draw 'text 25,82 "Anthony"' \
-draw 'text 27,83 "Anthony"' \
-draw 'text 28,85 "Anthony"' \
-fill white -draw 'text 25,85 "Anthony"' \
-crop 0x0 miff:- | display &
You can combine both the above outline and drop shadow effects
Centered on bottom edge..
convert logo: -font SheerBeauty -pointsize 30 \
-draw "gravity south \
text 0,10 'Copyright 2002'" \
miff:- | display &
Draw font from bottom right corner along the edge of the image...
This works by moving font just off the left edge of image,
then translating it the width of the image to the right hand edge.
convert logo: -font SheerBeauty -pointsize 30 \
-draw "gravity southwest rotate 270 \
translate -10,-10 text 0,%w 'Copyright 2002'" \
miff:- | display &
Center on left edge?
Draw font on top of a background image or tiled pattern
NB: you can not crop the final image after backaground is applied.
Also this will not work for a outline (hollow) font (see below).
convert -size 370x65 plasma: \
-font Weirdo -pointsize 72 \
-draw 'text 20,50 "Hello World"' \
miff:- | display &
Draw the letters using a tiled fill pattern
convert -size 600x120 xc:black \
-font Fleetwood -pointsize 100 \
-tile ~/icons/desc/cl-bgnd/display/colored_disks.jpg \
-draw 'text 20,80 "Psychedelic!"' \
-trim miff:- | display &
A patterned font on a background...
Replace the background in the last example with transparent, then composite it
on top of a background.
Draw a outlined font on a background.
It is actually a lot easier to do this with a solid font than and outline font
(see above). The solution is a complex multi-step process to "mask" out a
background image before drawing the outline font on that masked area. It does
NOT work for a outline font that also has "holes" in it, such as in the middle
of a "o" or a "p", Otherwise it works fairly well.
Get the outline font to draw,
convert convert -background transparent \
-font DoorJamb -pointsize 72 label:Test font.miff
First we need to remove the alpha channel, pick one of the following...
Directly
convert -font DoorJamb -pointsize 72 label:Test mask.miff
or indirectly (for images) by creating a white image and drawing on it
composite -size 1000x1000 xc:white -compose copy font.miff mask.miff
composite font.miff -compose atop mask.miff mask.miff
Now make all the outside parts transparent (two methods)
Note the extreme use of "-fuzz" to make the anti-aliased border blue for the
mask. Watch out for fill "leaks".
Either by making outside transparent...
convert mask.miff -fill transparent -fuzz 80% \
-draw 'color 0,0 floodfill' mask.miff
Or, just leave the insides of the font white....
convert mask.miff -fill black -fuzz 80% -draw 'color 0,0 floodfill' \
-fill blue -fuzz 0% -draw 'color 0,0 floodfill' \
-transparent blue mask.miff
NOTE: The first method above is almost a correct solution in itself, but it
loses any and all anti-alising at the boundaries, the second trys to only
white out the parts that need it (inside the font).
Create the final white-out mask. (all colors white, except transparency)
composite -size 1000x1000 xc:white -compose atop mask.miff mask.miff
Now stack and flatten the background image, white-out mask, and font image.
A geometry argument positions the mask and font images.
convert -size 370x80 tile:$HOME/icons/desc/gr-bgnd/curves.xpm \
-page +50+10 mask.miff font.miff -flatten \
result.jpg
Display a directory of fonts (with labels)
montage -tile 1x15 -geometry +0+1 -pointsize 36 \
`sh -c 'for i in *.ttf; do \\
echo -label $i -font $i label:ABC-xyz-0123; done'` \
-font Arial -pointsize 12 miff:- | display &
Note on internal workings... The "-label" is associated with the NEXT input
filename, while it is only "drawn" after all the image have been read and
assigned labels. That is no output is actually produced until all the input
has been read and labeled. Thus the final "-font" option is the font for
the drawing of the image labels. In other words this could be split into two
seperate steps (though it is much, much slower)...
convert -pointsize 24 `sh -c 'for i in *.ttf; do \\
echo -label $i -font $i label:ABC-xyz-0123; \\
done'` miff:- | \
montage -tile 1x15 -geometry +0+1 - -font Arial -pointsize 10 miff:- | \
display &
NOTE: montage's frame color is picked up from a source image. set it with
-background if it isn't correct.
Dimmed box for image labels...
The problem with writing text directly on a picture is that you can't be
sure the text will be readable in the color you have chossen, be it black,
white or other.
One simple solution is to use fake an outline font, (black border, white
inside) from a solid font, (See above). A more typical solution is to create
a dimmed box for the font to be draw into. That is the image is darkened
slightly to ensure white is visible.
Another good way to create a darkened box is using "-modulate"
convert -region 200x200+100+100 -modulate 20 logo: miff:- | display &
ImageMagick also supports specifying the level of transparency in colors.
For example, the color specification "#00000080" is 50% transparent black.
IE: draw a black rectangle that shows 50% of the color of the image below.
Idea: instead of a box, try using a fake outline font using a dimmed border
instead of black. WARNING, parts of border will dim more than others.
WARNING: I can NOT get this to work for fonts! it is either all black or all
completely transparent!
Attaching a label to image...
use montage...
montage -geometry +0+0 -tile 1x1 \
-label 'The netscape color map' netscape: miff:- | display
Append a label to bottom
convert -background white netscape: -font "Times-Roman"
label:"The netscape color map" -append miff:- | display
Add a border and write the text in it.
This unfortunatally adds a border to the top, which needs a extra chop.
On the other hand, you can expand it to add the border to all edges.
It also allows the use of "-gravity South" to center the text!
convert netscape: -bordercolor white -border 0x15 -chop 0x15 \
-gravity South -draw "text 0,4 'The netscape color map'" \
miff:- | display
-------------------------------------------------------------------------------
Affine Matrix
convert -affine sx,rx,ry,sy,tx,ty -draw 'text 100,100 "text message"' \
input.jpg output.jpg
The 's' parameters control scaling, the 'r' parameters control
translation, and the 't' parameters control coordinate translation.
The matrix is the same one used by Postscript and PDF. Also called a 2x3
matrix. Grab a copy of the Postscript or PDF reference - it's well documented
in there. It's also used by many other graphics libraries.
For a null affine matrix use 1.0 for scale, 0.0 for translate & rotate
Note ther may be easier ways...
convert -draw 'rotate 20 text 100,100 "text message"' input.jpg output.jpg
-------------------------------------------------------------------------------
Draw Primatives
Arc and Path...
-draw "arc x0,y0 x1,y1 a0,a1"
Arc is a legacy primitive and has since been replaces by PATH.
An example:
convert -draw "path M500,500 arc 50,50 0 25,25 100,100" \
logo: miff:- | display
(Result was not an arc...)
convert -draw "path M170,70 v-30 a30,30 0 0,0 -30,30 z" \
logo: miff:- | display
(No output!)
-------------------------------------------------------------------------------
"Drop Shadow" Generation..
convert -depth 8 -threshold 0 -negate source.png -bordercolor white \
-border 20x20 -gaussian 0x3 -shave 15x15 - | \
composite -gravity northwest source.png - out.png
Adjustments
- Set the background color with:
-bordercolor <color>
- Set the color of the drop shadow by adding:
-colorize <r>/<g>/<b>
before -negate, where <r>, <g>, and <b> are the
percentages of red, green, and blue of the desired color.
- Adjust the amount of blur with:
-gaussian <radius>x<sigma>
I find values from 0x3 to 0x5 to be useful.
- Empirical method to adjust the drop shadow's offset:
Set the parameters of -border to four times the desired offset in
pixels, and the parameters of -shave to three times the desired offset.
Notes
- The command is one line, it may have wrapped.
- The source image is referenced twice in the command line.
- This method fails when the amount of blur is greater than
the offset of the drop shadow.
-------------------------------------------------------------------------------
GIF Animation...
Refer to
http://www.sct.gu.edu.au/~anthony/wwwlab/gifanim/imagemagick.html
part of my Castles WWW Labortory
In short...
1/ put all animation options and sequence in a .anim file
See examples in above URL..
2/ then insert this into the convert command in the
correct directory so convert can find the images.
convert `cat image.anim` image_anim.gif
See the following script, which also allows comments in .anim file
http://www.sct.gu.edu.au/~anthony/icons/support/scripts/anim2gif
The "-dispose method number refers too...
0 => undefined (or just overwirte what has appeared)
1 => no disposal (same as 0)
2 => restore to background color
To unpack the frames of an animation you can use...
convert +adjoin animation.gif frame%02d.jpg
You may also like to look at my inverse script that trys to generate
a ".anim" file, to allow you to re-build the animation again afterward
http://www.sct.gu.edu.au/~anthony/icons/support/scripts/gif2anim
The -deconstruct option will remove areas that don't change from the GIF
animation sequence. That is the second and later frames only contain the part
of the GIF file that changed and not the whole frame.
The -coalesce does the reverse, expanding each frome to be the full image
that would appear at that pint in the animation. This allows easier editing of
the frames.
The program "gifsicle" is an alturnative, doing all the above and includes
the LZW compression. It was designed specifically for this task.
-------------------------------------------------------------------------------
Common color map for GIF Animation
It is easy to create a single global colormap for an image sequence
with ImageMagick:
convert -adjoin -color 256 *.gif animation.gif
The local color tables are still included in the GIF, however it matches that
of the global colormap. ImageMagick may be patched to not generate a local
colormap if a single global colormap applies to all images in the sequence.
Color map is also reduce to smallest map needed.
-------------------------------------------------------------------------------
GIF LZW compression
ImageMagick does not compress GIFs due to the patent on the GIF compression
algorithm owned by Unisys. It is due to expire next year, but until then it is
up to you to get the legal issues resolved.
Re-build ImageMagick with the --enable-lzw option to configure to enable.
Alturnative use the "gifsicle"...
gifsicle --batch -i *.gif
-------------------------------------------------------------------------------
PNG quality
When used with PNG output, quality is regarded as two decimal figures. The
first (tens) is the zlib compression level, 1-9. The second (ones digit) is
the PNG filtering type: 0 is none, 1 is "sub", 2 is "up", 3 is "average", 4 is
"Paeth", and 5 is "adaptive".
If your image has 256 or fewer colors, "none" filtering is generally best, and
the best compression is achieved with -quality 90. If the image is a natural
image (a photo), then use "adaptive" filtering with -quality 95.
If the ones digit is zero, then zlib uses the Huffman_only compression
strategy which is very fast and works fairly well on photos, so if you want
fast compression of photos, try -quality 1 (i.e., "sub" filter and
"Huffman_only" compression).
Later...
If you have an ImageMagick image with binary (on/off) transparency, the PNG
encoder will write it in an efficient manner, using the tRNS chunk instead of
a full alpha channel. But if any opacity value other than 0 or Maxvalue is
present, it'll write a PNG with an alpha channel. You can force this behavior
by using the "-type truecolormatte" option.
Glenn Randers-Pehrson <glennrp@comcast.net>
-------------------------------------------------------------------------------
WMF Scaling
The math in the WMF renderer is correct to render the WMF at the effective
"typeset" size specified in the metafile header. While the meaning of the
metafile header is subject to interpretation, I spend a fair amount of time
ensuring that it was right. ImageMagick and Adobe Illustrator appear to agree
on the rendered size.
The viewer provided with Windows XP appears to ignore the units from the
metafile header, and uses 1:1 scaling so WMFs are often claimed to be huge.
The WMF header includes units which should be used to obtain the width and
height of the image in inches. It is odd to claim this, but I think that
ImageMagick is more correct than Windows itself at calculating the WMF size.
Of course the metafile header was invented by Aldus, not Microsoft.
This is the math used:
image_width_inch = (double) wmf_width / units_per_inch;
image_height_inch = (double) wmf_height / units_per_inch;
image_width = image_width_inch * resolution_x;
image_height = image_height_inch * resolution_y;
where wmf_width and wmf_height specify the span of the vector data in width
and height, and units_per_inch (obtained from the metafile header) specifies
the number of WMF units per inch. The resolution_x & resolution_y parameters
are from ImageMagick's density setting.
The scaling applied to WMF files is based on 72 DPI when using convert, or
uses the resolution specified by the X11 server when the 'display' program is
used to display WMF on the screen.
In order to create a larger rendering, you can use -density to specify a
larger value. For example '-density 144' produces an image which is twice as
large in each dimension. If you know the units per inch value from the
metafile header, then you could apply a -density value which reverses the
units_per_inch division.
-------------------------------------------------------------------------------
Faster JPEG resizing
The -size option tells the IM jpeg decoder that the image being read
will be resized later. This lets it run faster by avoiding returning
full-resolution images, for later resizing.
For example...
convert -size 120x120 cockatoo.jpg -resize 120x120 \
+profile "*" cockatoo_thumb.gif
This may not give as nice as a result as just the -resize filter itself, but
it is a lot faster. If you like you could also use -size to scale part way and
-resize to finalize. For example if you are starting with a 3000x2000 jpeg
and want a 120x80 thumbnail, you could use "-size 480x320" then "-resize
120x80"
NOTE: -resize uses the filter selected with -filter while -scale uses a
simple fast scaling method. -resize & -filter give you more control
but might consume more CPU time.
-------------------------------------------------------------------------------
Image Comments
Remove a comment: mogrify +comment image.png
Replace a comment: mogrify +comment -comment "a new comment" image.png
Read a comment: identify -format "%f: %c" image.png
Remove profiles: mogrify +profile "*" image.jpg
NOTE: morgify replaces the existing image to just copy to a new file use
convert instead specify the destination image as a extra argument on the end.
WARNING: imagemagic decodes and re-encodes the image, degrading jpeg images.
To avoid this use programs from the libjpeg package. with will just copy the
image without decoding as the comment are added or removed.
JPEG:
read comments: rdjpgcom image.jpg
remove comments: wrjpgcom -replace -comment '' image.jpg > new_image.jpg
remove profiles: jpegtran -copy none image.jpg > new_image.jpg
-------------------------------------------------------------------------------
Output older BMP format
As was mentiond previously on the list, ImageMagick 5.4.9 supports writing BMP
versions up to version 4, which supports application profiles. It chooses the
lowest BMP version that supports the features required not to loose
information. Maybe these applications make assumptions about the format,
ignoring offset information, and don't deal with the profiles correctly.
The PNG file contains a gAMA and cHRM chunk (gamma and chromaticity
information) either of which forces "convert" to write a BMP-4.
To get a BMP3 you need to get rid of that information.
convert button.png PPM:- | convert PPM:- button.bmp
will get rid of profiles, chromaticity, gamma, and transparency, title,
copyright info, and should produce a BMP3 instead of a BMP4.
-------------------------------------------------------------------------------
Display constantly says "not support an image matte (PsuedoColor)"
You can get rid of the message by using the +matte option
I.E. display +matte file.gif
You don't need to worry about this on 24 bit color terminals
Same goes to remove this message for the Animate program.
-------------------------------------------------------------------------------
Postscript to Images (anti-aliasing fonts)
If you just convert a postscript file to an image directly (using
ghostscript), you will get it at 72dpi resolution (yuck). A better idea is
to do this at a larger resolution and then shrink it so that the edges are
properly anti-aliased...
Example:
convert -density 288 -geometry 25% foo.ps foo.jpg
Convert is a ImageMagick command. It calls ghostscript to convert
postscript to pbmplus format before converting (and shinking) to the final
jpeg image.
NOTE: Density 288 is 4 times the normal 72 dpi screen (and image)
resolution. Also the bigger you render the images the more memory and CPU
power you need ... 2x2 or 3x3 is probably good enough for web pages.
ASIDE: If you need more antialiasing, you can blur the image a little bit
before you reduce its size.
ASIDE: if you want to resize the image, without the anti-alias color merging
use -sample instead of -geometry. The former simply copies the nearest
pixel color into the new pixel.
NOTE: "-filter point -geometry WxH" and "-sample WxH" are equivilent.
Richard Bollinger <rabollinger@attbi.com> Notes...
Running ghostscript directly is _much_ more efficient..
convert -density 300x300 -compress Group4 file.pdf file.tif
required an 84mb temporary file, consumed 120 cpu seconds, paged like crazy and
ran for 12 minutes on a two page pdf.
gs -sDEVICE=tiffg4 -r300x300 -dNOPAUSE -sOutputFile=file.tif \
file.pdf </dev/null
required no temporary file, consumed less than 1 cpu second and ran for less
than 2 seconds on the same file.
-------------------------------------------------------------------------------
Convert sequence of postscript to PDF
WORK IN PROGRESS
Convert pages to grayscale images (anti-aliased)
mogrify -colorspace gray -density 288 -geometry 25% *.ps *.png
then convert images to a PDF
convert -sample 50% *.png newsletter.pdf
-------------------------------------------------------------------------------
IM Speed
> Converting a 14Mb 9400x9400 truecolor jpg to 1024x1024 truecolor png
> ...
> Why is ImageMagick 35x slower than GDI+API?
Sounds like you should use GDI+API. ImageMagick is a robust general
solution to a number of image processing problems. We traded off
speed for robustness and image quality. Image reduction, for example,
defaults to the Lanczos finite impulse response filter which is much more
computationally expensive than the bicubic filter GDI uses.
You can reduce the ImageMagick memory requirements by setting the cache
threshold to a very low value and make IM a bit faster by selecting a faster
algorithm.
convert -cache 1 -filter blackman -geometry 1024x1024 image.jpg image.png
-------------------------------------------------------------------------------
Current IM faults...
As of version 5.4.9
The filename is included in internal "text" to "postscript" conversion!
Using the command...
convert txt:text_file -geometry +50+80 miff:- | display
The string "text_file" will be prepended to the text file being passed to
the postscript converter (internally) and then to the output image.
This is definately a bug!
Gradent Behaviour
If I run the command...
convert -size 200x200 gradient:red-black miff:- | display
Instead of getting a nice image shading from red, through dark red to
black, I get one that shades from red, pink, blue, dark cyan, dark
green, very dark khaki, and finally black.
Display "quit" behaviour.
Display quits if you hit space on the last frame in a sequence (YUCK)
And 'q' which almost all image displayers understands to mean quit,
doesn't quit in imagemagick display. ESC doesn't do it either!
This is technically not a BUG, just an very HUGE annoyance.
-----
As of version 5.5.7
Bugs "gradient behaviour" and "text file name" fixed.
"Display QUIT" is not fixed
First line of text has base line ON the top border
(only the decents of letters like 'p', 'g', 'y' are visible on the first line)
convert txt:t miff:- | display
Disposal is reset by -delay option if -disposal is NOT give with that option.
Source: http://www.sct.gu.edu.au/~anthony/info/graphics/imagemagick.hints