>K  + Z D ImageMagick - Image Processing and Display Package9VL






>Contents




>Introduction

KPerlMagick,Rversion 5.11, is an objected-oriented PerlJinterface to ImageMagick. Use the moduleFto read, manipulate, or write an image or image sequence from within aFPerl script. This makes it very suitable for Web CGI scripts. You mustHhave ImageMagick 5.2.0 or above and Perl version 5.002 or greaterLinstalled on your system for either of these utilities to work. Perl versionF5.005_02 or greater is required for PerlMagick to work on an NT system.
K


There are a number of useful scripts available to show you the valueofIPerlMagick. You can do Web based image manipulation and conversionwithNMogrifyMagick,or useIL-systemsNto create images of plants using mathematical constructs, and finally navigateIthrough collections of thumbnail images and select the image to view withtheEWebMagickImage Navigator.

You can try PerlMagick from your Web browser at the ImageMagickStudio. Or, you can see-examples&of select PerlMagick functions.O

An object-oriented Python interface to ImageMagick is also available,Tsee PythonMagick.

/Back to Contents
 
 

>Installation

UNIX
H


 ImageMagick must already be installed on your system. Next,get theJPerlMagick*distribution and unpack it as shown below:E

    gunzip -c PerlMagick-5.11.tar.gz | tar -xvf -&    cd PerlMagick
FNext, edit Makefile.PL and change LIBS and INC to include theHappropriate path information to the required libMagick library.HYou will also need paths to JPEG, PNG, TIFF, etc. delegates if they wereMincluded with your installed version of ImageMagick. Build and install it like this:(
    perl Makefile.PL    make%    make install
IFor Unix, you typically need to be root to install the software.OThere are ways around this. Consult the Perl manual pages for more information.!

Windows NT / Windows 95H

 ImageMagick must already be installed on your system. Also, the#ImageMagick source distribution forAWindowsINT is required. You must also have the nmake from the VisualFC++ or J++ development environment. Copy \bin\IMagick.dll and\bin\X11.dll0to a directory in your dynamic load path such asc:\perl\site\5.00502. Next, type%

    cd PerlMagick/    copy Makefile.nt Makefile.PL#    perl Makefile.PL    nmake&    nmake install
#Running the Regression Tests/

 To verify a correct installation, type'

    make test
MUse nmake test under Windows. There are ao few demonstration scriptsJavailable to exercise many of the functions PerlMagick can perform.Type
    cd demo    make
FYou are now ready to utilize the PerlMagick methods from withinyour Perl scripts.
/Back to Contents
 
 

>Overview

HAny script that wants to use PerlMagick methods must first defineIthe methods within its namespace and instantiate an image object. Do this with:
*
    use Image::Magick;3    $image=Image::Magick->new;
TThe new method takes the same parameters as SetAttribute. For example,I
    $image=Image::Magick->new(size=>'384x256');
INext you will want to read an image or image sequence, manipulate it, and:then display or write it. The input and output methods forPerlMagickRare defined in Read or Write an Image. See SetGan Image Attribute for methods that affect the way an image is reador written. Refer to2Manipulate an Image for a listLof methods to transform an image. Get an Image Attribute=describes how to retrieve an attribute for an image. Refer toCreateGan Image Montage for details about tiling your images as thumbnailsHon a background. Finally, some methods do not neatly fit into any of the!categories just mentioned. Review)Miscellaneous Methodsfor a list of these methods.L

Once you are finished with a PerlMagick object you should considerKdestroying it. Each image in an image sequence is stored in virtual memory.FThis can potentially add up to mega-bytes of memory. Upon destroying aPerlMagickMobject, the memory is returned for use by other Perl methods. The recommended0way to destroy an object is with undef:+

    undef $image;
ITo delete all the images but retain the Image::Magick object use,
    undef @$image;
Fand finally, to delete a single image from a multi-image sequence, use0
    undef $image->[x];
IThe next section illustrates how to use various PerlMagick methods to manipulate an image sequence.G

Some of the PerlMagick methods require external programs suchasNGhostscript. This may require an explicit path in your PATH environment'variable to work properly. For example,H

    $ENV{PATH}='/bin:/usr/bin:/usr/local/bin';

/Back to Contents
 
 

>Example$Script

2Here is an example script to get you started:
-
    #!/usr/local/bin/perl%    use Image::Magick;"    my($image, $x);/    $image = Image::Magick->new;I    $x = $image->Read('girl.png', 'logo.png', 'rose.png');%    warn "$x" if "$x";F    $x = $image->Crop(geometry=>'100x100"+1"00"+1"00');%    warn "$x" if "$x";/    $x = $image->Write('x.png');+    warn "$x" if "$x";
GThe script reads three images, crops them, and writes a single image asIa GIF animation sequence. In many cases you may want to access individualDimages of a sequence. The next example illustrates how this is done:-
    #!/usr/local/bin/perl%    use Image::Magick;&    my($image, $p, $q);.    $image = new Image::Magick;*    $image->Read('x1.png');*    $image->Read('j*.jpg');3    $image->Read('k.miff[1, 5, 3]');$    $image->Contrast;2    for ($x = 0; $image->[x]; $x++)    {d      $image->[x]->Frame('100x200') if $image->[x]->Get('magick') eq 'GIF';Y      undef $image->[x] if $image->[x]->Get('columns') < 100;    }$    $p = $image->[1];[    $p->Draw(stroke=>'red', primitive=>'rectangle', points=>20,20 100,100');&    $q = $p->Montage();     undef $image;-    $q->Write('x.miff');
GSuppose you want to start out with a 100 by 100 pixel white canvas witha red pixel in the center. Try4
    $image = Image::Magick->new;0    $image->Set(size=>'100x100');1    $image->ReadImage('xc:white');<    $image->Set('pixel[49,49]'=>'red');
=Or suppose you want to convert your color image to grayscale:C
    $image->Quantize(colorspace=>'gray');
6Here we annotate an image with a Taipai TrueType font:K
    $text = "\\0x17ef\\0x30ec\\0x25ec\\0x23ef\\0x17ec";i    $image->Annotate(font=>'@kai.ttf', pointsize=>40, stroke=>'green', text=>$text);
EOther clever things you can do with PerlMagick objects includei
    $i = $#$p"+1";   # return the number of images associated with object pV    push(@$q, @$p);  # push the images from object p onto object qj    undef @$p;       # delete the images but not the object pd    p->Convolve([1, 2, 1, 2, 4, 2, 1, 2, 1]);   # 3x3 Gaussian kernel

/Back to Contents
 
 

>Read/or Write an Image

GUse the methods listed below to either read, write, or display an imageor image sequence.
(((+)-;,.
Read or Write Methods
MethodParametersReturn ValueDescription
Readone or more filenamesthe number of images read read an image or image sequence
Writefilenamethe number of images written write an image or image sequence
Displayserver namethe number of images displayed display the image or image sequence to an X server
Animateserver namethe number of images animated animate image sequence to an X server
A

For convenience, methods Write, Display, andAnimateIcan take any parameter that SetAttribute knows about. For example,U

    $image->Write(filename=>'image.png', compress=>'None');
LUse - as the filename to method Read to read from standard8in or to method Write to write to standard out:'
    binmode STDOUT;0    $image->Write(.png:-');
?To read an image in the GIF format from a PERL filehandle, use:C
    $image = Image::Magick->new(magick=>'GIF');+    open(DATA, 'image.png');,    $image->Read(file=>DATA);%    close(DATA);
>To write an image in the PNG format to a PERL filehandle, use:0
    $filename = "image.png";,    open(DATA, ">$filename");B    $image->Write(file=>DATA, filename=>$filename);%    close(DATA);
FYou can optionally add Image to any method name. For example,ReadImage*is an alias for method Read.
/Back to Contents
 
 

>Manipulate&an Image

IOnce you create an image with, for example, method ReadImage youImay want to operate on it. Below is a list of all the image manipulationshmethods available to you with PerlMagick. There are examples of select>PerlMagick methods. Here is an example call to an imagemanipulation method:
B
    $image->Crop(geometry=>'100x100"+1"0+20');7    $image->[x]->Frame("100x200");
DAnd here is a list of other image manipulation methods you can call:-PH%IM2$M#DF8/$O)=-3JM*<,P>XK84IIM5\NB".#('$9:ZFI"Q=J?!8=F0M=HH1L1Q(Q$KHP5LOI0"41#I:2,%:"JN5BW)MH
Image Manipulation Methods
MethodParametersDescription
AddNoisenoise=>{Uniform, Gaussian, Multiplicative, Impulse, Laplacian, Poisson}add noise to an image
Annotatetext=>string, font=>string, pointsize=>integer,Kdensity=>geometry, stroke=>colorname, fill=>colorname,Ibox=>colorname, geometry=>geometry, server=>{string,M@filename}, gravity=>{NorthWest, North, NorthEast, West, Center, East,CSouthWest, South, SouthEast}, x=>integer, y=>integer,degrees=>doubleannotate an image with text.
Blurorder=>integerblur the image. Good order values are odd numbers from 3 to 31.
Bordergeometry=>geometry, width=>integer, height=>integer,color=colornamesurround the image with a border of color
Charcoalorder=>integersimulate a charcoal drawing
Chopgeometry=>geometry, width=>integer, height=>integer,)x=>integer, y=>integerchop an image
Clone make a copy an image
Coalesce merge a sequence of images
ColorFloodfillgeometry=>geometry, x=>integer, y=>integer,8fill=colorname, bordercolor=colornamechanges the color value of any pixel that matches the color of theHtarget pixel and is a neighbor. If you specify a border color, the colorDvalue is changed for any neighbor pixel that is not that color.
Colorizecolor=>colorname, fill=>colornamecolorize the image with the fill color
Commentstringadd a comment to your image
Compositecompose=>{Over, In, Out, Atop, Xor, Plus, Minus, Add, Subtract, Difference,FBumpmap, Replace, ReplaceRed, ReplaceGreen, ReplaceBlue, ReplaceMatte,IBlend, Displace}, image=>image-handle, geometry=>geometry, x=>integer,Fy=>integer, gravity=>{NorthWest, North, NorthEast, West, Center, East,%SouthWest, South, SouthEast}composite one image onto another
Condense compress image to take up the least amount of memory
Contrastsharpen=>{True, False}enhance or reduce the image contrast
Convolvecoefficients=>array of float valuesapply a convolution kernel to the image. Given a kernel order,Myou would supply order*order float values (e.g. 3x3 implies 9 values).
Cropgeometry=>geometry, width=>integer, height=>integer,)x=>integer, y=>integercrop an image
CycleColormapamount=>integerdisplace image colormap by amount
Deconstruct break down an image sequence into constituent parts
Despeckle reduce the speckles within an image
Drawprimitive=>{point, line, rectangle, arc, ellipse, circle, polyline, polygon,Lbezier, color, matte, text, image, @filename}, points=>string,?method={Point, Replace, Floodfill, FillToBorder, Reset},Lstroke=>colorname, fill=>colorname, tile=>image-handle,Nlinewidth=>float, bordercolor=>colorname, server=>string,;x=>float, y=>float, rotate=>floatannotate an image with one or more graphic primitives
Edgeorder=>integerdetect edges within the image. Good order values are odd numbers from 3 to 31.
Embossorder=>integeremboss the image. Good order values are odd numbers from 3 to 31.
Enhance apply a digital filter to enhance a noisy image
Equalize perform histogram equalization to the image
Flip create a mirror image by reflecting the image scanlines in thevertical direction
Flop create a mirror image by reflecting the image scanlines in thehorizontal direction
Framegeometry=>geometry, width=>integer, height=>integer,Jinner=>integer, outer=>integer, color=>colornamesurround the image with an ornamental border
Gammagamma=>double, red=>double, green=>double, blue=>double gamma correct the image
GaussianBlurgeometry=>geometry, width=>double, sigma=>doubleblur the image with a gaussian operator of the given width and standard deviation (sigma).
Implodefactor=>percentageimplode image pixels about the center
Labelstringassign a label to an image
Layerlayer={Red, Green, Blue, Matte}extract a layer from the image
Magnify double the size of an image
Mapimage=>image-handle, dither={True, False}choose a particular set of colors from this image
MatteFloodfillgeometry=>geometry, x=>integer, y=>integer, matte=integer,!bordercolor=colornamechanges the matte value of any pixel that matches the color of theHtarget pixel and is a neighbor. If you specify a border color, the matteDvalue is changed for any neighbor pixel that is not that color.
MedianFilterorder=>integerreplace each pixel with the median intensity pixel of a neighborhood.4Good order values are odd numbers from 3 to 31.
Minify half the size of an image
Modulatebrightness=>double, saturation=>double, hue=>doublevary the brightness, saturation, and hue of an image
Negategray=>{True, False}replace every pixel with its complementary color (white becomes black,yellow becomes blue, etc.)
Normalize transform image to span the full range of color values
OilPaintradius=>integersimulate an oil painting
Opaquecolor=>colorname, fill=>colornamechange this color to the fill color within the image
Quantizecolors=>integer, colorspace=>{RGB, Gray, Transparent, OHTA,NXYZ, YCbCr, YIQ, YPbPr, YUV, CMYK}, treedepth=> integer, dither=>{True,IFalse}, measure_error=>{True, False}, global_colormap=>{True, False}preferred number of colors in the image
Raisegeometry=>geometry, width=>integer, height=>integer,?x=>integer, y=>integer, raise=>{True, False}lighten or darken image edges to create a 3-D effect
ReduceNoiseorder=>integerreduce noise in the image with a noise peak elimination filter
Rollgeometry=>geometry, x=>integer, y=>integerroll an image vertically or horizontally
Rotatedegrees=>double, crop=>{True, False}, sharpen=>{True, False}roll an image vertically or horizontally
Samplegeometry=>geometry, width=>integer, height=>integerscale image with pixel sampling
Scalegeometry=>geometry, width=>integer, height=>integerscale image to desired size
Segmentcolorspace=>{RGB, Gray, Transparent, OHTA, XYZ, YCbCr, YCC, YIQ, YPbPr,TYUV, CMYK}, verbose={True, False}, cluster=>double, smooth=doublesegment an image by analyzing the histograms of the color components/and identifying units that are homogeneous
Shadegeometry=>geometry, azimuth=>double, elevation=>double,color=>{true, false} shade the image using a distant light source
Sharpenorder=>integersharpen the image. Good order values are odd numbers from 3 to 31.
Sheargeometry=>geometry, x=>double, y=>double, crop=>{true, false}shear the image along the X or Y axis by a positive or negative shear angle
Signature generate an MD5 signature for the image
Solarizefactor=>percentagenegate all pixels above the threshold level
Spreadamount=>integerdisplace image pixels by a random amount
Stereoimage=>image-handlecombines two images and produces a single image that is the composite/of a left and right image of a stereo pair
Steganoimage=>image-handle, offset=integerhide a digital watermark within the image
Swirldegrees=>doubleswirl image pixels about the center
Texturetexture=>image-handlename of texture to tile onto the image background
Thresholdthreshold=>integerthreshold the image
Transformcrop=>geometry, geometry=>geometry, filter=>{Point, Box,JTriangle, Hermite, Hanning, Hamming, Blackman, Gaussian, Quadratic, Cubic,-Catrom, Mitchell, Lanczos, Bessel, Sinc}crop or resize an image with a fully-qualified geometry specification
Transparent color=>colornamemake this color transparent within the image
Trim remove edges that are the background color from the image
Wavegeometry=>geometry, amplitude=>double, wavelength=>doublealter an image along a sine wave
Zoomgeometry=>geometry, width=>integer, height=>integer,Mfilter=>{Point, Box, Triangle, Hermite, Hanning, Hamming, Blackman, Gaussian,TQuadratic, Cubic, Catrom, Mitchell, Lanczos, Bessel, Sinc}, blur=>doublescale image to desired size. Specify blur > 1 for blurry or< 1 for sharp
D

Note, that the geometry parameter is a short cut for thewidthNand height parameters (e.g. geometry=>'106x80' is equivalent$to width=>106, height=>80).R

You can specify @filename in both Annotate and Draw.JThis reads the text or graphic primitive instructions from a file on disk. For example,H

   $image->Draw(pen=>'red', primitive=>'rectangle', `     points=>'20,20 100,100  40,40 200,200  60,60 300,300');
Is eqivalent toI
   $image->Draw(pen=>'red', primitive=>'@draw.txt');
=Where draw.txt is a file on disk that contains this:%
  rectangle 20, 20 100, 100   rectangle 40, 40 200, 200&  rectangle 60, 60 300, 300
KThe text parameter for methods, Annotate, Comment,Draw,Gand Label can include the image filename, type, width, height,For other image attribute by embedding these special format characters:0
    %b   file size+    %d   directory4    %e   filename extension*    %f   filename(    %h   height(    %m   magick-    %p   page number.    %s   scene number1    %t   top of filename'    %w   width.    %x   x resolution.    %y   y resolution)    \n   newline7    \r   carriage return
For example,%
  text=>"%m:%f %wx%h"

Kproduces an annotation of MIFF:bird.miff 512x480 for an image titledbird.miff.and whose width is 512 and height is 480.
M


You can optionally add Image to any method name. For example,TrimImage%is an alias for method Trim.8

Most of the attributes listed above have an analog in#convert.OSee the documentation for a more detailed description of these attributes.

/Back to Contents
 
 

>Set0an Image Attribute

DUse method Set to set an image attribute. For example,
4
    $image->Set(dither=>'True');5    $image->[$x]->Set(delay=>3);
;And here is a list of all the image attributes you can set:#3':#GL;"GB+*!:9'9''::+"/G7M"I5K5('9@%&4*(::"3$'6
Image Attributes
AttributeValuesDescription
adjoin{True, False}join images into a single multi-image file
antialias{True, False}remove pixel aliasing
backgroundstringimage background color
blue_primaryx-value, y-valuechromaticity blue primary point (e.g. 0.15, 0.06)
bordercolorstringset the image border color
cache_thresholdintegerImage pixels are stored in memory until 80 megabytes of memory haveIbeen consumed. Subsequent pixel operations are cached on disk. OperationsGto memory are significantly faster but if your computer does not have aKsufficient amount of free memory you may want to lower this threshold.
colormap[i]stringcolor name (e.g. red) or hex value (e.g. #ccc) at position i
colorspace{RGB, CMYK}type of colorspace
compressNone, BZip, Fax, Group4, JPEG, LZW, Runlength, Ziptype of image compression
delayintegerthis many 1/100ths of a second\fP must expire before displaying thenext image in a sequence
densitygeometryvertical and horizontal resolution in pixels of the image
dispose{0, 1, 2, 3, 4}GIF disposal method
dither{True, False}apply error diffusion to the image
displaystringspecifies the X server to contact
filefilehandleset the image filehandle
filenamestringset the image filename
fontstringuse this font when annotating the image with text
fuzzintegercolors within this distance are considered equal
green_primaryx-value, y-valuechromaticity green primary point (e.g. 0.3, 0.6)
interlace{None, Line, Plane, Partition}the type of interlacing scheme
iterationsintegeradd Netscape loop extension to your GIF animation
loopintegeradd Netscape loop extension to your GIF animation
magickstringset the image format
matte{True, False}True if the image has transparency
mattecolorstringset the image matte color
monochrome{True, False}transform the image to black and white
page{ Letter, Tabloid, Ledger, Legal, Statement, Executive, A3, A4, A5,5B4, B5, Folio, Quarto, 10x14} or geometrypreferred size and location of an image canvas
pencolorcolor name (e.g. red) or hex value (e.g. #ccc) for annotating or changingopaque color
pixel[x, y]stringcolor name (e.g. red) or hex value (e.g. #ccc) at position (x,y)
pointsizeintegerpointsize of the Postscript or TrueType font
preview{ Rotate, Shear, Roll, Hue, Saturation, Brightness, Gamma, Spiff, Dull,PGrayscale, Quantize, Despeckle, ReduceNoise, AddNoise, Sharpen, Blur, Threshold,JEdgeDetect, Spread, Solarize, Shade, Raise, Segment, Swirl, Implode, Wave,+OilPaint, CharcoalDrawing, JPEG} type of preview for the Preview image format
qualityintegerJPEG/MIFF/PNG compression level
red_primaryx-value, y-valuechromaticity red primary point (e.g. 0.64, 0.33)
rendering_intent{Undefined, Saturation, Perceptual, Absolute, Relative}the type of rendering intent
sceneintegerimage scene number
subimageintegersubimage of an image sequence
subrangeintegernumber of images relative to the base image
serverstringspecifies the X server to contact
sizestringwidth and height of a raw image
tilestringtile name
texturestringname of texture to tile onto the image background
units{ Undefined, PixelsPerInch, PixelsPerCentimeters}units of image resolution
verbose{True, False}print detailed information about the image
viewstringFlashPix viewing parameters
white_pointx-value, y-valuechromaticity white point (e.g. 0.3127, 0.329)
D

Note, that the geometry parameter is a short cut for thewidthNand height parameters (e.g. geometry=>'106x80' is equivalent$to width=>106, height=>80).=

SetAttribute is an alias for method Set.8

Most of the attributes listed above have an analog in#convert.OSee the documentation for a more detailed description of these attributes.

(Back to Contents
 
 

>Get0an Image Attribute

DUse method Get to get an image attribute. For example,
U
    ($a, $b, $c) = $image->Get('colorspace', 'magick', 'adjoin');>    $width = $image->[3]->Get('columns');
HIn addition to all the attributes listed in Set an Image7Attribute, you can get these additional attributes:#253-0-)!1I5FG10,+G3""
Image Attributes
AttributeValuesDescription
base_columnsintegerbase image width (before transformations)
base_filenamestringbase image filename (before transformations)
base_rowsintegerbase image height (before transformations)
class{Direct, Pseudo}image class
colorsintegernumber of unique colors in the image
commentstringimage comment
columnsintegerimage width
depthintegerimage depth
directorystringtile names from within an image montage
filesizeintegernumber of bytes of the image on disk
formatstringget the descriptive image format
gammadoublegamma level of the image
geometrystringimage geometry
heightintegerthe number of rows or height of an image
labelstringimage label
meandoublethe mean error per pixel computed when an image is color reduced
montagegeometrytile size and offset within an image montage
normalized_maxdoublethe normalized max error per pixel computed when an image is color reduced
normalized_meandoublethe normalized mean error per pixel computed when an image is color reduced
rowsintegerthe number of rows or height of an image
signaturestringMD5 signature associated with the image
tainted{True, False}True if the image has been modified
textstringany text associated with the image
type{Bilevel, Grayscale, Palette, TrueColor, MatteType, ColorSeparation}image type
widthintegerthe number of columns or width of an image
x-resolutionintegerx resolution of the image
y-resolutionintegery resolution of the image
=

GetAttribute is an alias for method Get.8

Most of the attributes listed above have an analog in#convert.OSee the documentation for a more detailed description of these attributes.

(Back to Contents
 
 

>Create.an Image Montage

LUse method Montage to create a composite image by combining severalJseparate images. The images are tiled on the composite image with the nameSof the image optionally appearing just below the individual tile. For example,
e
    $image->Montage(geometry=>'160x160', tile=>'2x2', texture=>'granite:');
>And here is a list of Montage parameters you can set:%F#5KG4#&"%56":+,5
Montage Parameters
ParameterValuesDescription
backgroundcolorX11 color name
borderwidthintegerimage border width
compose{Over, In, Out, Atop, Xor, Plus, Minus, Add, Subtract, Difference,;Bumpmap, Replace, MatteReplace, Mask, Blend, Displace}composite operator
filenamestringname of montage image
fillcolorfill color for annotations
pointsize
fontstringX11 font name
framegeometrysurround the image with an ornamental border
geometrygeometrypreferred tile and border size of each tile of the composite image
gravity{NorthWest, North, NorthEast, West, Center, East, SouthWest, South,SouthEast}direction image gravitates to within a tile
labelstringassign a label to an image
mode{Frame, Unframe, Concatenate}thumbnail framing options
strokecolorstroke color for annotations
pointsizeintegerpointsize of the Postscript or TrueType font
shadow{True, False}add a shadow beneath a tile to simulate depth
penstringcolor for annotation text
pointsize
texturestringname of texture to tile onto the image background
tilegeometrynumber of tiles per row and column
titlestringassign a title to the image montage
transparentstringmake this color transparent within the image
D

Note, that the geometry parameter is a short cut for thewidthNand height parameters (e.g. geometry=>'106x80' is equivalent$to width=>106, height=>80).A

MontageImage is an alias for method Montage.8

Most of the attributes listed above have an analog in#montage.OSee the documentation for a more detailed description of these attributes.

/Back to Contents
 
 

>Miscellaneous%Methods

DThe Append method append a set of images. For example,
G
    $x = $image->Append(stack=>{true,false});
Fappends all the images associated with object $image. All theIinput images must have the same width or height. Images of the same widthOare stacked top-to-bottom. Images of the same height are stacked left-to-right.MIf the stack parameter is false, rectangular images are stacked left-to-rightotherwise top-to-bottom.
GThe Average method averages a set of images. For example,
5
    $x = $image->Average();
?averages all the images associated with object $image.
GThe Morph method morphs a set of images. Both the image pixelsMand size are linearly interpolated to give the appearance of a meta-morphosis from one image to the next:
I
    $x = $image->Morph(frames=>integer);
Gwhere frames is the number of in-between images to generate. The default is 1.;

Mosaic create an mosaic from an image sequence.M

Method Mogrify is a single entry point for the image manipulationImethods (Manipulate an Image). The parameters are theGname of a method followed by any parameters the method may require. For$example, these calls are equivalent:4

    $image->Crop('340x256+0+0');@    $image->Mogrify('crop', '340x256+0+0');
KMethod MogrifyRegion applies a transform to a region of the image.GIt is similiar to Mogrify but begins with the region geometry.HFor example, suppose you want to brighten a 100x100 region of your imageat location (40, 50):a
    $image->MogrifyRegion('100x100+40+50', 'modulate', brightness=>50);

CThe Clone method copies a set of images. For example,
3
    $p = $image->Clone();
Fcopies all the images from object $q to $p. Use thisImethod for multi-image sequences. PerlMagick transparently createsFa linked list from an image array. If two locations in the array pointtoKthe same object, the linked list goes into an infinite loop and your script.will run forever until interrupted. Instead of/
    push(@$images, $image);Q    push(@$images, $image);  # warning duplicate object
(use cloning to prevent an infinite loop:/
    push(@$images, $image);*    $clone=$image->Clone();X    push(@$images, $clone);  # same image but different object
OPing accepts one or more image file names and returns their respectiveMwidth, height, size in bytes, and format (e.g. GIF, JPEG, etc.). For example,g
    ($width, $height, $size, $format) = split(',', $image->Ping('logo.png'));
KThis is a more efficient and less memory intensive way to query if an imageIexists and what its characteristics are. Note, only information about the4first image in a multi-frame image file is returned.F

You can optionally add Image to any method name above. ForAexample, PingImage is an alias for method Ping.h

Use RemoteCommand to send a command to an already running displayHor animate application. The only parameter is1the name of the image file to display or animate.F

Finally, for convenience, method QueryColor accepts one orFmore color names or hex value and returns their respective red, green,and blue color values:b

    ($red, $green, $blue, $opacity) = split(', ', $image->QueryColor('cyan'));f    ($red, $green, $blue, $opacity) = split(', ', $image->QueryColor('#716bae'));

(Back to Contents
 
 

>Handling$Errors

NAll PerlMagick methods return an undefined string context upon success.IIf any problems occur, the error is returned as a string with an embeddedInumeric status code. A status code less than 400 is a warning. This meansGthat the operation did not complete but was recoverable to some degree.NA numeric code greater or equal to 400 is an error and indicates the operationRfailed completely. Here is how errors are returned for the different methods:
!Here is an example error message:A
    Error 400: Memory allocation failed
+Below is a list of error and warning codes:*5A%,:U&+55A%,:U&+55
Error and Warning Codes
CodeMnemonicDescription
0Successmethod completed without an error or warning
300ResourceLimitWarninga program resource is exhausted (e.g. not enough memory)
305XServerWarningan X resource is unavailable
310OptionWarninga command-line option was malformed
315DelegateWarningan ImageMagick delegate returned a warning
320MissingDelegateWarningthe image type can not be read or written because the appropriate Delegateis missing
325CorruptImageWarningthe image file may be corrupt
330FileOpenWarningthe image file could not be opened
335BlobWarninga binary large object could not be allocated
340CacheWarningpixels could not be saved to the pixel cache
400ResourceLimitErrora program resource is exhausted (e.g. not enough memory)
405XServerErroran X resource is unavailable
410OptionErrora command-line option was malformed
415DelegateErroran ImageMagick delegate returned a warning
420MissingDelegateErrorthe image type can not be read or written because the appropriate Delegateis missing
425CorruptImageErrorthe image file may be corrupt
430FileOpenErrorthe image file could not be opened
435BlobErrora binary large object could not be allocated
440CacheErrorpixels could not be saved to the pixel cache
C

The following illustrates how you can use a numeric status code:6

    $x = $image->Read('rose.png');!    $x =~ /(\d+)/;P    die "unable to continue" if ($1 == ResourceLimitError);

(Back to Contents
 
 

>Working(with Blobs

FA blob contains data that directly represent a particular image formatHin memory instead of on disk. PerlMagick supports blobs in any ofFthese image formats and provides methods to9convert a blob to or from a particular image format.
0>@2.
Blob Methods
MethodParametersReturn ValueDescription
ImageToBlobany image attributean array of image data in the respective image formatconvert an image or image sequence to an array of blobs
BlobToImageone or more blobsthe number of blobs converted to an imageconvert one or more blobs to an image
K

ImageToBlob returns the image data in their respective formats.GYou can then print it, save it to an ODBC database, write it to a file, or pipe it to a display program:7

    @blobs = $image->ImageToBlob();6    open(DISPLAY,"| display -") || die;#    binmode DISPLAY;+    print DISPLAY $blobs[0];'    close DISPLAY;
HMethod BlobToImage returns an image or image sequence convertedfrom the supplied blob:.
    $blob=$db->GetImage();<    $image=Image::Magick->new(magick=>'jpg');4    $image->BlobToImage($blob);

(Back to Contents
 
 

>Copyright

1Copyright (C) 2000 ImageMagick Studio

HPermission is hereby granted, free of charge, to any person obtainingJa copy of this software and associated documentation files ("PerlMagick"),Gto deal in PerlMagick without restriction, including without limitationHthe rights to use, copy, modify, merge, publish, distribute, sublicense,Nand/or sell copies of PerlMagick, and to permit persons to whom the PerlMagickDis furnished to do so, subject to the following conditions:

JThe above copyright notice and this permission notice shall be included=in all copies or substantial portions of PerlMagick.

JThe software is provided "as is", without warranty of any kind, expressKor implied, including but not limited to the warranties of merchantability,Ffitness for a particular purpose and noninfringement.In no event shallGImageMagick Studio be liable for any claim, damages or other liability,Fwhether in an action of contract, tort or otherwise, arising from, outXof or in connection with PerlMagick or the use or other dealings in PerlMagick.

GExcept as contained in this notice, the name of the E. I. du Pont deLNemours and Company shall not be used in advertising or otherwise to promoteQthe sale, use or other dealings in PerlMagick without prior written authorization%from the ImageMagick Studio.

(Back to Contents
Home Page>Image manipulation software that works like magic.