| 1 | <?xml version="1.0" encoding="UTF-8"?> |
|---|
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|---|
| 3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> |
|---|
| 4 | <head> |
|---|
| 5 | <style type="text/css" media="screen,projection"><!-- |
|---|
| 6 | @import url("../www/magick.css"); |
|---|
| 7 | //--></style> |
|---|
| 8 | <meta name="verify-v1" content="g222frIIxcQTrvDR3NBRUSKP3AnMNoqxOkIniCEkV7U=" /> |
|---|
| 9 | <link rel="meta" type="application/rdf+xml" title="ICI" href="http://imagemagick.org/ici.rdf" /> |
|---|
| 10 | <title>ImageMagick: PerlMagick, Perl API for ImageMagick</title> |
|---|
| 11 | <meta http-equiv="Content-Language" content="en-US"/> |
|---|
| 12 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
|---|
| 13 | <meta http-equiv="Reply-to" content="magick-users@imagemagick.org"/> |
|---|
| 14 | <meta name="Generator" content="PHP"/> |
|---|
| 15 | <meta name="Keywords" content="perlmagick, perl, api, for, imagemagick, ImageMagick, ImageMagic, MagickCore, MagickWand, PerlMagick, Magick++, RMagick, PythonMagick, JMagick, TclMagick, Image, Magick, Magic, Wand"/> |
|---|
| 16 | <meta name="Description" content="ImageMagick® is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (about 100) including GIF, JPEG, JPEG-2000, PNG, PDF, PhotoCD, TIFF, and DPX. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves. ImageMagick is free software delivered as a ready-to-run binary distribution or as source code that you can freely use, copy, modify, and distribute. Its license is compatible with the GPL. It runs on all major operating systems. The functionality of ImageMagick is typically utilized from the command line or you can use the features from programs written in your favorite programming language. Choose from these interfaces: MagickCore (C), MagickWand (C), ChMagick (Ch), Magick++ (C++), JMagick (Java), L-Magick (Lisp), PascalMagick (Pascal), PerlMagick (Perl), MagickWand for PHP (PHP), PythonMagick (Python), RMagick (Ruby), or TclMagick (Tcl/TK). With a language interface, use ImageMagick to modify or create images automagically and dynamically."/> |
|---|
| 17 | <meta name="Rating" content="GENERAL"/> |
|---|
| 18 | <meta name="Robots" content="INDEX, FOLLOW"/> |
|---|
| 19 | <meta name="Generator" content="ImageMagick Studio LLC"/> |
|---|
| 20 | <meta name="Author" content="ImageMagick Studio LLC"/> |
|---|
| 21 | <meta name="Revisit-after" content="2 DAYS"/> |
|---|
| 22 | <meta name="Resource-type" content="document"/> |
|---|
| 23 | <meta name="Copyright" content="Copyright (c) 1999-2007 ImageMagick Studio LLC"/> |
|---|
| 24 | <meta name="Distribution" content="Global"/> |
|---|
| 25 | <link rel="shortcut icon" href="../images/wand.ico" type="images/vnd.microsoft.icon"/> |
|---|
| 26 | </head> |
|---|
| 27 | |
|---|
| 28 | <body id="www-imagemagick-org"> |
|---|
| 29 | <table id="titlebar" style="width: 100%;background-color: #f5f5f5" cellpadding="0" cellspacing="0" border="0" summary="ImageMagick"> |
|---|
| 30 | <tbody> |
|---|
| 31 | <tr valign="top"> |
|---|
| 32 | <td align="left"><a href="../index.html"><img id="titlebar-west" src="../images/script.png" alt="[ImageMagick]" width="350" height="60" border="0" vspace="28" name="titlebar-west"/></a></td> |
|---|
| 33 | <td align="left"><a href="https://secure.networkredux.com/affiliate/idevaffiliate.html?id=146" target="126549663"><img id="titlebar-west" src="../images/networkredux.png" alt="[sponsor]" border="0" vspace="45" name="titlebar-west"/></a></td> |
|---|
| 34 | <td width="99%"><br /></td> |
|---|
| 35 | <td style="background-color: white" align="right"><a href="../index.html"><img src="../images/sprite.jpg" alt="" width="114" height="118" border="0" name="titlebar-east"/></a></td> |
|---|
| 36 | <td style="background-color: white" align="right"><a href="../index.html"><img id="titlebar-east" src="../images/logo.jpg" alt="" width="114" height="118" border="0" name="titlebar-east"/></a></td> |
|---|
| 37 | </tr> |
|---|
| 38 | </tbody> |
|---|
| 39 | </table> |
|---|
| 40 | |
|---|
| 41 | <table style="width: 100%" border="0" cellpadding="0" cellspacing="0" summary=""> |
|---|
| 42 | <tbody> |
|---|
| 43 | |
|---|
| 44 | <tr valign="top" style="height: 100%;"> |
|---|
| 45 | <td id="menu" width="1%" height="100%"> |
|---|
| 46 | <p><a href="#main">Skip to page contents</a></p> |
|---|
| 47 | <span>[</span> |
|---|
| 48 | <a href="../index.html">About ImageMagick</a> |
|---|
| 49 | <a href="../www/command-line-tools.html">Command-line Tools</a> |
|---|
| 50 | <a href="../www/command-line-processing.html" class="sub">Processing</a> |
|---|
| 51 | <a href="../www/command-line-options.html" class="sub">Options</a> |
|---|
| 52 | <a href="http://www.imagemagick.org/Usage/" target="1462883662" class="sub">Usage</a> |
|---|
| 53 | <a href="../www/api.html">Program Interfaces</a> |
|---|
| 54 | <a href="../www/magick-wand.html" class="sub">MagickWand</a> |
|---|
| 55 | <a href="../www/magick-core.html" class="sub">MagickCore</a> |
|---|
| 56 | <a href="../www/perl-magick.html" class="sub">PerlMagick</a> |
|---|
| 57 | <a href="../Magick++/" target="1821835731" class="sub">Magick++</a> |
|---|
| 58 | <a href="../www/architecture.html">Architecture</a> |
|---|
| 59 | <span>]</span><br /><span>[</span> |
|---|
| 60 | <a href="../www/install-source.html">Install from Source</a> |
|---|
| 61 | <a href="../www/install-source.html#unix" class="sub">Unix</a> |
|---|
| 62 | <a href="../www/install-source.html#windows" class="sub">Windows</a> |
|---|
| 63 | <a href="../www/binary-releases.html">Binary Releases</a> |
|---|
| 64 | <a href="../www/binary-releases.html#unix" class="sub">Unix</a> |
|---|
| 65 | <a href="../www/binary-releases.html#macosx" class="sub">Mac OS X</a> |
|---|
| 66 | <a href="../www/binary-releases.html#windows" class="sub">Windows</a> |
|---|
| 67 | <a href="../www/resources.html">Resources</a> |
|---|
| 68 | <span>]</span><br /><span>[</span> |
|---|
| 69 | <a href="../www/download.html">Download</a> |
|---|
| 70 | <span>]</span><br /><span>[</span> |
|---|
| 71 | <a href="../www/sitemap.html">Site Map</a> |
|---|
| 72 | <a href="../www/links.html" class="sub">Links</a> |
|---|
| 73 | <span>]</span><br /><br /><span>[</span> |
|---|
| 74 | <a href="../www/sponsors.html">Sponsors</a> |
|---|
| 75 | <a href="http://www.aoemedia.de" class="sponsor" target="sponsor">TYPO3 Agentur</a><!-- 200807010000 --> |
|---|
| 76 | <span>]</span> |
|---|
| 77 | </td> |
|---|
| 78 | |
|---|
| 79 | <td id="main" valign="top"> |
|---|
| 80 | <p class="navigation-index">[<a href="#installation">Installation</a> • <a href="#overview">Overview</a> • <a href="#example">Example Script</a> • <a href="#read">Read or Write an Image</a> • <a href="#manipulate">Manipulate an Image</a> • <a href="#set-attribute">Set an Image Attribute</a> • <a href="#get-attribute">Get an Image Attribute</a> • <a href="#montage">Create an Image Montage</a> • <a href="#blobs">Working with Blobs</a> • <a href="#direct-access">Direct-access to Image Pixels</a> • <a href="#miscellaneous">Miscellaneous Methods</a> • <a href="#exceptions">Handling Exceptions</a>]</p> |
|---|
| 81 | |
|---|
| 82 | <a name="introduction"></a> |
|---|
| 83 | <p><a href="../www/download.html">PerlMagick</a> is an objected-oriented <a href="http://www.perl.com/perl/">Perl</a> interface to ImageMagick. Use the module to read, manipulate, or write an image or image sequence from within a Perl script. This makes it very suitable for Web CGI scripts. You must have ImageMagick 6.2.0 or above and Perl version 5.005_02 or greater installed on your system for either of these utilities to work.</p> |
|---|
| 84 | |
|---|
| 85 | <p>There are a number of useful scripts available to show you the value of PerlMagick. You can do Web based image manipulation and conversion with <a href="http://www.imagemagick.org/download/perl" target="674791694">MagickStudio</a>, or use <a href="https://www.imagemagick.org/subversion/ImageMagick/trunk/PerlMagick/demo/" target="289975600">L-systems</a> to create images of plants using mathematical constructs, and finally navigate through collections of thumbnail images and select the image to view with the <a href="http://webmagick.sourceforge.net/" target="884339392">WebMagick Image Navigator</a>.</p> |
|---|
| 86 | |
|---|
| 87 | <p>You can try PerlMagick from your Web browser at the <a href="http://www.imagemagick.org/MagickStudio/scripts/MagickStudio.cgi" target="933920990">ImageMagick Studio</a>. Or, you can see <a href="../www/examples.html">examples</a> of select PerlMagick functions.</p> |
|---|
| 88 | |
|---|
| 89 | <div style="margin: auto;"> |
|---|
| 90 | <h2><a name="installation"></a>Installation</h2> |
|---|
| 91 | </div> |
|---|
| 92 | |
|---|
| 93 | <p><b>UNIX</b></p> |
|---|
| 94 | |
|---|
| 95 | <p>The following instructions for Unix apply only to the unbundled PerlMagick as obtained from CPAN. PerlMagick is included as a subdirectory (PerlMagick) of the ImageMagick source distribution, and may be configured and built using the instructions provided in the ImageMagick distribution's README.txt file. It is usually most convenient to install PerlMagick as part of the ImageMagick distribution.</p> |
|---|
| 96 | |
|---|
| 97 | <p>ImageMagick must already be installed on your system. Next, get |
|---|
| 98 | the <a href="../www/download.html">PerlMagick</a> distribution corresponding to the installed ImageMagick distribution (e.g. PerlMagick 6.22 for ImageMagick 6.2.2) and unpack it as shown below:</p> |
|---|
| 99 | |
|---|
| 100 | <pre class="text"> |
|---|
| 101 | gunzip -c PerlMagick-6.22.tar.gz • tar -xvf - |
|---|
| 102 | cd PerlMagick |
|---|
| 103 | </pre> |
|---|
| 104 | |
|---|
| 105 | <p>Next, edit <kbd>Makefile.PL</kbd> and change LIBS and INC to include the appropriate path information to the required <kbd>libMagick</kbd> library. You will also need paths to JPEG, PNG, TIFF, etc. delegates if they were included with your installed version of ImageMagick. Build and install it like this:</p> |
|---|
| 106 | |
|---|
| 107 | <pre class="text"> |
|---|
| 108 | perl Makefile.PL |
|---|
| 109 | make |
|---|
| 110 | make install |
|---|
| 111 | </pre> |
|---|
| 112 | |
|---|
| 113 | <p>For Unix, you typically need to be <kbd>root</kbd> to install the software. There are ways around this. Consult the Perl manual pages for more information.</p> |
|---|
| 114 | |
|---|
| 115 | <p><b>Windows XP / Windows 2000</b></p> |
|---|
| 116 | |
|---|
| 117 | <p>ImageMagick must already be installed on your system. Also, the ImageMagick source distribution for <a href="../www/download.html">Windows 2000</a> is required. You must also have the <kbd>nmake</kbd> from the Visual C++ or J++ development environment. Copy <kbd>\bin\IMagick.dll</kbd> and <kbd>\bin\X11.dll</kbd> to a directory in your dynamic load path such as <kbd>c:\perl\site\5.00502</kbd>.</p> |
|---|
| 118 | |
|---|
| 119 | <p>Next, type</p> |
|---|
| 120 | |
|---|
| 121 | <pre class="text"> |
|---|
| 122 | cd PerlMagick |
|---|
| 123 | copy Makefile.nt Makefile.PL |
|---|
| 124 | perl Makefile.PL |
|---|
| 125 | nmake |
|---|
| 126 | nmake install |
|---|
| 127 | </pre> |
|---|
| 128 | |
|---|
| 129 | <p>See the <a href="http://www.dylanbeattie.net/magick/">PerlMagick Windows HowTo</a> page for further installation instructions.</p> |
|---|
| 130 | |
|---|
| 131 | <p><b>Running the Regression Tests</b></p> |
|---|
| 132 | |
|---|
| 133 | <p>To verify a correct installation, type</p> |
|---|
| 134 | |
|---|
| 135 | <pre class="text"> |
|---|
| 136 | make test |
|---|
| 137 | </pre> |
|---|
| 138 | |
|---|
| 139 | <p>Use <kbd>nmake test</kbd> under Windows. There are a few demonstration scripts available to exercise many of the functions PerlMagick can perform. Type</p> |
|---|
| 140 | |
|---|
| 141 | <pre class="text"> |
|---|
| 142 | cd demo |
|---|
| 143 | make |
|---|
| 144 | </pre> |
|---|
| 145 | |
|---|
| 146 | <p>You are now ready to utilize the PerlMagick methods from within your Perl scripts.</p> |
|---|
| 147 | |
|---|
| 148 | <div style="margin: auto;"> |
|---|
| 149 | <h2><a name="overview"></a>Overview</h2> |
|---|
| 150 | </div> |
|---|
| 151 | |
|---|
| 152 | <p>Any script that wants to use PerlMagick methods must first define the methods within its namespace and instantiate an image object. Do this with:</p> |
|---|
| 153 | |
|---|
| 154 | <pre class="code"> |
|---|
| 155 | use Image::Magick; |
|---|
| 156 | |
|---|
| 157 | $image=Image::Magick->new; |
|---|
| 158 | </pre> |
|---|
| 159 | |
|---|
| 160 | <p>The new() method takes the same parameters as <a href="#set-attribute">SetAttribute</a> . For example,</p> |
|---|
| 161 | |
|---|
| 162 | <pre class="code"> |
|---|
| 163 | $image=Image::Magick->new(size=>'384x256'); |
|---|
| 164 | </pre> |
|---|
| 165 | |
|---|
| 166 | <p>Next you will want to read an image or image sequence, manipulate it, and then display or write it. The input and output methods for PerlMagick are defined in <a href="#read">Read or Write an Image</a>. See <a href="#set-attribute">Set an Image Attribute</a> for methods that affect the way an image is read or written. Refer to <a href="#manipulate">Manipulate an Image</a> for a list of methods to transform an image. <a href="#get-attribute">Get an Image Attribute</a> describes how to retrieve an attribute for an image. Refer to <a href="#montage">Create an Image Montage</a> for details about tiling your images as thumbnails on a background. Finally, some methods do not neatly fit into any of the categories just mentioned. Review <a href="#misc">Miscellaneous Methods</a> for a list of these methods.</p> |
|---|
| 167 | |
|---|
| 168 | <p>Once you are finished with a PerlMagick object you should consider destroying it. Each image in an image sequence is stored in virtual memory. This can potentially add up to mega-bytes of memory. Upon destroying a PerlMagick object, the memory is returned for use by other Perl methods. The recommended way to destroy an object is with <kbd>undef</kbd>:</p> |
|---|
| 169 | |
|---|
| 170 | <pre class="code"> |
|---|
| 171 | undef $image; |
|---|
| 172 | </pre> |
|---|
| 173 | |
|---|
| 174 | <p>To delete all the images but retain the <kbd>Image::Magick</kbd> object use</p> |
|---|
| 175 | |
|---|
| 176 | <pre class="code"> |
|---|
| 177 | @$image = (); |
|---|
| 178 | </pre> |
|---|
| 179 | |
|---|
| 180 | <p>and finally, to delete a single image from a multi-image sequence, use</p> |
|---|
| 181 | |
|---|
| 182 | <pre class="code"> |
|---|
| 183 | undef $image->[$x]; |
|---|
| 184 | </pre> |
|---|
| 185 | |
|---|
| 186 | <p>The next section illustrates how to use various PerlMagick methods to manipulate an image sequence.</p> |
|---|
| 187 | |
|---|
| 188 | <p>Some of the PerlMagick methods require external programs such as <a href="http://www.cs.wisc.edu/~ghost/">Ghostscript</a>. This may require an explicit path in your PATH environment variable to work properly. For example,</p> |
|---|
| 189 | |
|---|
| 190 | <pre class="text"> |
|---|
| 191 | $ENV{PATH}='/../bin:/usr/bin:/usr/local/bin'; |
|---|
| 192 | </pre> |
|---|
| 193 | |
|---|
| 194 | <div style="margin: auto;"> |
|---|
| 195 | <h2><a name="example"></a>Example Script</h2> |
|---|
| 196 | </div> |
|---|
| 197 | |
|---|
| 198 | <p>Here is an example script to get you started:</p> |
|---|
| 199 | |
|---|
| 200 | <pre class="code"> |
|---|
| 201 | #!/usr/local/bin/perl |
|---|
| 202 | use Image::Magick;<br /> |
|---|
| 203 | my($image, $x);<br /> |
|---|
| 204 | $image = Image::Magick->new; |
|---|
| 205 | $x = $image->Read('girl.png', 'logo.png', 'rose.png'); |
|---|
| 206 | warn "$x" if "$x";<br /> |
|---|
| 207 | $x = $image->Crop(geometry=>'100x100+100+100'); |
|---|
| 208 | warn "$x" if "$x";<br /> |
|---|
| 209 | $x = $image->Write('x.png'); |
|---|
| 210 | warn "$x" if "$x"; |
|---|
| 211 | </pre> |
|---|
| 212 | |
|---|
| 213 | <p>The script reads three images, crops them, and writes a single image as a GIF animation sequence. In many cases you may want to access individual images of a sequence. The next example illustrates how this is done:</p> |
|---|
| 214 | |
|---|
| 215 | <pre class="code"> |
|---|
| 216 | #!/usr/local/bin/perl |
|---|
| 217 | use Image::Magick;<br /> |
|---|
| 218 | my($image, $p, $q);<br /> |
|---|
| 219 | $image = new Image::Magick; |
|---|
| 220 | $image->Read('x1.png'); |
|---|
| 221 | $image->Read('j*.jpg'); |
|---|
| 222 | $image->Read('k.miff[1, 5, 3]'); |
|---|
| 223 | $image->Contrast(); |
|---|
| 224 | for ($x = 0; $image->[$x]; $x++) |
|---|
| 225 | { |
|---|
| 226 | $image->[$x]->Frame('100x200') if $image->[$x]->Get('magick') eq 'GIF'; |
|---|
| 227 | undef $image->[$x] if $image->[$x]->Get('columns') < 100; |
|---|
| 228 | } |
|---|
| 229 | $p = $image->[1]; |
|---|
| 230 | $p->Draw(stroke=>'red', primitive=>'rectangle', points=>20,20 100,100'); |
|---|
| 231 | $q = $p->Montage(); |
|---|
| 232 | undef $image; |
|---|
| 233 | $q->Write('x.miff'); |
|---|
| 234 | </pre> |
|---|
| 235 | |
|---|
| 236 | <p>Suppose you want to start out with a 100 by 100 pixel white canvas with a red pixel in the center. Try</p> |
|---|
| 237 | |
|---|
| 238 | <pre class="code"> |
|---|
| 239 | $image = Image::Magick->new; |
|---|
| 240 | $image->Set(size=>'100x100'); |
|---|
| 241 | $image->ReadImage('xc:white'); |
|---|
| 242 | $image->Set('pixel[49,49]'=>'red'); |
|---|
| 243 | </pre> |
|---|
| 244 | |
|---|
| 245 | <p>Here we reduce the intensity of the red component at (1,1) by half:</p> |
|---|
| 246 | |
|---|
| 247 | <pre class="code"> |
|---|
| 248 | @pixels= image->GetPixel(x=>1,y=>1); |
|---|
| 249 | $pixels[0]*=0.5; |
|---|
| 250 | $im->SetPixel(x=>1,y=>1,color=>\@pixels); |
|---|
| 251 | </pre> |
|---|
| 252 | |
|---|
| 253 | <p>Or suppose you want to convert your color image to grayscale:</p> |
|---|
| 254 | |
|---|
| 255 | <pre class="code"> |
|---|
| 256 | $image->Quantize(colorspace=>'gray'); |
|---|
| 257 | </pre> |
|---|
| 258 | |
|---|
| 259 | <p>Let's annotate an image with a Taipai TrueType font:</p> |
|---|
| 260 | |
|---|
| 261 | <pre class="code"> |
|---|
| 262 | $text = 'Works like magick!'; |
|---|
| 263 | $image->Annotate(font=>'kai.ttf', pointsize=>40, fill=>'green', text=>$text); |
|---|
| 264 | </pre> |
|---|
| 265 | |
|---|
| 266 | <p>Perhaps you want to extract all the pixel intensities from an image and write them to STDOUT:</p> |
|---|
| 267 | |
|---|
| 268 | <pre class="code"> |
|---|
| 269 | @pixels = $image->GetPixels(map=>'I', height=>$height, width=>$width, normalize=>true); |
|---|
| 270 | binmode STDOUT; |
|---|
| 271 | print pack('B*',join('',@pixels)); |
|---|
| 272 | </pre> |
|---|
| 273 | |
|---|
| 274 | <p>Other clever things you can do with a PerlMagick objects include</p> |
|---|
| 275 | |
|---|
| 276 | <pre class="code"> |
|---|
| 277 | $i = $#$p"+1"; # return the number of images associated with object p |
|---|
| 278 | push(@$q, @$p); # push the images from object p onto object q |
|---|
| 279 | @$p = (); # delete the images but not the object p |
|---|
| 280 | $p->Convolve([1, 2, 1, 2, 4, 2, 1, 2, 1]); # 3x3 Gaussian kernel |
|---|
| 281 | </pre> |
|---|
| 282 | |
|---|
| 283 | <div style="margin: auto;"> |
|---|
| 284 | <h2><a name="read"></a>Read or Write an Image</h2> |
|---|
| 285 | </div> |
|---|
| 286 | |
|---|
| 287 | <p>Use the methods listed below to either read, write, or display an image or image sequence:</p> |
|---|
| 288 | |
|---|
| 289 | <table id="table" cellpadding="2" cellspacing="0" style="width: 93%"> |
|---|
| 290 | <caption>Read or Write Methods</caption> |
|---|
| 291 | <tbody> |
|---|
| 292 | <tr> |
|---|
| 293 | <th>Method</th> |
|---|
| 294 | <th>Parameters</th> |
|---|
| 295 | <th>Return Value</th> |
|---|
| 296 | <th style="width: 50%">Description</th> |
|---|
| 297 | </tr> |
|---|
| 298 | |
|---|
| 299 | <tr> |
|---|
| 300 | <td valign="top">Read</td> |
|---|
| 301 | <td valign="top">one or more filenames</td> |
|---|
| 302 | <td valign="top">the number of images read</td> |
|---|
| 303 | <td valign="top">read an image or image sequence</td> |
|---|
| 304 | </tr> |
|---|
| 305 | |
|---|
| 306 | <tr> |
|---|
| 307 | <td valign="top">Write</td> |
|---|
| 308 | <td valign="top">filename</td> |
|---|
| 309 | <td valign="top">the number of images written</td> |
|---|
| 310 | <td valign="top">write an image or image sequence</td> |
|---|
| 311 | </tr> |
|---|
| 312 | |
|---|
| 313 | <tr> |
|---|
| 314 | <td valign="top">Display</td> |
|---|
| 315 | <td valign="top">server name</td> |
|---|
| 316 | <td valign="top">the number of images displayed</td> |
|---|
| 317 | <td valign="top">display the image or image sequence to an X server</td> |
|---|
| 318 | </tr> |
|---|
| 319 | |
|---|
| 320 | <tr> |
|---|
| 321 | <td valign="top">Animate</td> |
|---|
| 322 | <td valign="top">server name</td> |
|---|
| 323 | <td valign="top">the number of images animated</td> |
|---|
| 324 | <td valign="top">animate image sequence to an X server</td> |
|---|
| 325 | </tr> |
|---|
| 326 | </tbody> |
|---|
| 327 | </table> |
|---|
| 328 | |
|---|
| 329 | <p>For convenience, methods Write(), Display(), and Animate() can take any parameter that <a href="#set-attribute">SetAttribute</a> knows about. For example,</p> |
|---|
| 330 | |
|---|
| 331 | <pre class="code"> |
|---|
| 332 | $image->Write(filename=>'image.png', compression=>'None'); |
|---|
| 333 | </pre> |
|---|
| 334 | |
|---|
| 335 | <p>Use <kbd>-</kbd> as the filename to method Read() to read from standard in or to method Write() to write to standard out:</p> |
|---|
| 336 | |
|---|
| 337 | <pre class="code"> |
|---|
| 338 | binmode STDOUT; |
|---|
| 339 | $image->Write('png:-'); |
|---|
| 340 | </pre> |
|---|
| 341 | |
|---|
| 342 | <p>To read an image in the GIF format from a PERL filehandle, use:</p> |
|---|
| 343 | |
|---|
| 344 | <pre class="code"> |
|---|
| 345 | $image = Image::Magick->new; |
|---|
| 346 | open(IMAGE, 'image.gif'); |
|---|
| 347 | $image->Read(file=>\*IMAGE); |
|---|
| 348 | close(IMAGE); |
|---|
| 349 | </pre> |
|---|
| 350 | |
|---|
| 351 | <p>To write an image in the PNG format to a PERL filehandle, use:</p> |
|---|
| 352 | |
|---|
| 353 | <pre class="code"> |
|---|
| 354 | $filename = "image.png"; |
|---|
| 355 | open(IMAGE, ">$filename"); |
|---|
| 356 | $image->Write(file=>\*IMAGE, filename=>$filename); |
|---|
| 357 | close(IMAGE); |
|---|
| 358 | </pre> |
|---|
| 359 | |
|---|
| 360 | <p>If <kbd>%0Nd, %0No, or %0Nx</kbd> appears in the filename, it is interpreted as a printf format specification and the specification is replaced with the specified decimal, octal, or hexadecimal encoding of the scene number. For example,</p> |
|---|
| 361 | |
|---|
| 362 | <pre class="text"> |
|---|
| 363 | image%03d.miff |
|---|
| 364 | </pre> |
|---|
| 365 | |
|---|
| 366 | <p>converts files image000.miff, image001.miff, etc.</p> |
|---|
| 367 | |
|---|
| 368 | <p>You can optionally add <i>Image</i> to any method name. For example, ReadImage() is an alias for method Read().</p> |
|---|
| 369 | |
|---|
| 370 | |
|---|
| 371 | <div style="margin: auto;"> |
|---|
| 372 | <h2><a name="manipulate"></a>Manipulate an Image</h2> |
|---|
| 373 | </div> |
|---|
| 374 | |
|---|
| 375 | <p>Once you create an image with, for example, method ReadImage() you may want to operate on it. Below is a list of all the image manipulations methods available to you with PerlMagick. There are <a href="../www/examples.html">examples</a> of select PerlMagick methods. Here is an example call to an image manipulation method:</p> |
|---|
| 376 | |
|---|
| 377 | <pre class="code"> |
|---|
| 378 | $image->Crop(geometry=>'100x100+10+20'); |
|---|
| 379 | $image->[$x]->Frame("100x200"); |
|---|
| 380 | </pre> |
|---|
| 381 | |
|---|
| 382 | <p>And here is a list of other image manipulation methods you can call:</p> |
|---|
| 383 | |
|---|
| 384 | <table id="table" cellpadding="2" cellspacing="0" style="width: 93%"> |
|---|
| 385 | <caption>Image Manipulation Methods</caption> |
|---|
| 386 | <tbody> |
|---|
| 387 | <tr> |
|---|
| 388 | <th>Method</th> |
|---|
| 389 | <th style="width: 40%">Parameters</th> |
|---|
| 390 | <th style="width: 40%">Description</th> |
|---|
| 391 | </tr> |
|---|
| 392 | |
|---|
| 393 | <tr> |
|---|
| 394 | <td valign="top">AdaptiveBlur</td> |
|---|
| 395 | <td valign="top">geometry=><i>geometry</i>, radius=><i>double</i>, sigma=><i>double</i>, channel=>{All, Default, Alpha, Black, Blue, Cyan, Gray, Green, Index, Magenta, Opacity, Red, Yellow}</td> |
|---|
| 396 | <td valign="top">adaptively blur the image with a Gaussian operator of the given radius and standard deviation (sigma). Decrease the effect near edges.</td> |
|---|
| 397 | </tr> |
|---|
| 398 | |
|---|
| 399 | <tr> |
|---|
| 400 | <td valign="top">AdaptiveResize</td> |
|---|
| 401 | <td valign="top">geometry=><i>geometry</i>, width=><i>integer</i>, height=><i>integer</i></td> |
|---|
| 402 | <td valign="top">resize image with data dependent trianglulation.</td> |
|---|
| 403 | </tr> |
|---|
| 404 | |
|---|
| 405 | <tr> |
|---|
| 406 | <td valign="top">AdaptiveSharpen</td> |
|---|
| 407 | <td valign="top">geometry=><i>geometry</i>, radius=><i>double</i>, sigma=><i>double</i>, channel=>{All, Default, Alpha, Black, Blue, Cyan, Gray, Green, Index, Magenta, Opacity, Red, Yellow}</td> |
|---|
| 408 | <td valign="top">adaptively sharpen the image with a Gaussian operator of the given radius and standard deviation (sigma). Increase the effect near edges.</td> |
|---|
| 409 | </tr> |
|---|
| 410 | |
|---|
| 411 | <tr> |
|---|
| 412 | <td valign="top">AdaptiveThreshold</td> |
|---|
| 413 | <td valign="top">geometry=><i>geometry</i>, width=><i>integer</i>, height=><i>integer</i>, offset=><i>integer</i></td> |
|---|
| 414 | <td valign="top">local adaptive thresholding.</td> |
|---|
| 415 | </tr> |
|---|
| 416 | |
|---|
| 417 | <tr> |
|---|
| 418 | <td valign="top">AddNoise</td> |
|---|
| 419 | <td valign="top">noise=>{Uniform, Gaussian, Multiplicative, Impulse, Laplacian, Poisson}, channel=>{All, Default, Alpha, Black, Blue, Cyan, Gray, Green, Index, Magenta, Opacity, Red, Yellow}</td> |
|---|
| 420 | <td valign="top">add noise to an image</td> |
|---|
| 421 | </tr> |
|---|
| 422 | |
|---|
| 423 | <tr> |
|---|
| 424 | <td valign="top">AffineTransform</td> |
|---|
| 425 | <td valign="top">affine=><i>array of float values</i>, translate=><i>float, float</i>, scale=> <i>float, float</i>, rotate=><i>float</i>, skewX=><i>float</i>, skewY=><i>float</i>, interpolate={Average, Bicubic, Bilinear, Filter, Integer, Mesh, NearestNeighbor}, background=><i><a href="../www/color.html">color name</a></i></td> |
|---|
| 426 | <td valign="top">affine transform image</td> |
|---|
| 427 | </tr> |
|---|
| 428 | |
|---|
| 429 | <tr> |
|---|
| 430 | <td valign="top">Annotate</td> |
|---|
| 431 | <td valign="top">text=><i>string</i>, font=><i>string</i>, family=><i>string</i>, style=>{Normal, Italic, Oblique, Any}, stretch=>{Normal, UltraCondensed, ExtraCondensed, Condensed, SemiCondensed, SemiExpanded, Expanded, ExtraExpanded, UltraExpanded}, weight=><i>integer</i>, pointsize=><i>integer</i>, density=><i>geometry</i>, stroke=><i><a href="../www/color.html">color name</a></i>, strokewidth=><i>integer</i>, fill=><i><a href="../www/color.html">color name</a></i>, undercolor=><i><a href="../www/color.html">color name</a></i>, geometry=><i>geometry</i>, gravity=>{NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast}, antialias=>{true, false}, x=><i>integer</i>, y=><i>integer</i>, affine=><i>array of float values</i>, translate=><i>float, float</i>, scale=><i>float, float</i>, rotate=><i>float</i>. skewX=><i>float</i>, skewY=> <i>float</i>, align=>{Left, Center, Right}, encoding=>{UTF-8}</td> |
|---|
| 432 | <td valign="top">annotate an image with text. See <a href="#misc">QueryFontMetrics</a> to get font metrics without rendering any text.</td> |
|---|
| 433 | </tr> |
|---|
| 434 | |
|---|
| 435 | <tr> |
|---|
| 436 | <td valign="top">AutoOrient</td> |
|---|
| 437 | <td valign="top"><br /></td> |
|---|
| 438 | <td valign="top">automatically orient the image</td> |
|---|
| 439 | </tr> |
|---|
| 440 | |
|---|
| 441 | <tr> |
|---|
| 442 | <td valign="top">BlackThreshold</td> |
|---|
| 443 | <td valign="top">threshold=><i>string</i></td> |
|---|
| 444 | <td valign="top">force all pixels below the threshold intensity into black</td> |
|---|
| 445 | </tr> |
|---|
| 446 | |
|---|
| 447 | <tr> |
|---|
| 448 | <td valign="top">Blur</td> |
|---|
| 449 | <td valign="top">geometry=><i>geometry</i>, radius=><i>double</i>, sigma=><i>double</i>, channel=>{All, Default, Alpha, Black, Blue, Cyan, Gray, Green, Index, Magenta, Opacity, Red, Yellow}</td> |
|---|
| 450 | <td valign="top">reduce image noise and reduce detail levels with a Gaussian operator of the given radius and standard deviation (sigma).</td> |
|---|
| 451 | </tr> |
|---|
| 452 | |
|---|
| 453 | <tr> |
|---|
| 454 | <td valign="top">Border</td> |
|---|
| 455 | <td valign="top">geometry=><i>geometry</i>, width=><i>integer</i>, height=><i>integer</i>, bordercolor=><i><a href="../www/color.html">color name</a></i>, compose=>{Undefined, Add, Atop, Blend, Bumpmap, Clear, ColorBurn, ColorDodge, Colorize, CopyBlack, CopyBlue, CopyCyan, CopyGreen, Copy, CopyMagenta, CopyOpacity, CopyRed, CopyYellow, Darken, Dst, Difference, Displace, Dissolve, DstAtop, DstIn, DstOut, DstOver, Dst, Exclusion, HardLight, Hue, In, Lighten, Luminize, Minus, Modulate, Multiply, None, Out, Overlay, Over, Plus, ReplaceCompositeOp, Saturate, Screen, SoftLight, Src, SrcAtop, SrcIn, SrcOut, SrcOver, Src, Subtract, Threshold, Xor },</td> |
|---|
| 456 | <td valign="top">surround the image with a border of color</td> |
|---|
| 457 | </tr> |
|---|
| 458 | |
|---|
| 459 | <tr> |
|---|
| 460 | <td valign="top">Charcoal</td> |
|---|
| 461 | <td valign="top">geometry=><i>geometry</i>, radius=><i>double</i>, sigma=><i>double</i></td> |
|---|
| 462 | <td valign="top">simulate a charcoal drawing</td> |
|---|
| 463 | </tr> |
|---|
| 464 | |
|---|
| 465 | <tr> |
|---|
| 466 | <td valign="top">Chop</td> |
|---|
| 467 | <td valign="top">geometry=><i>geometry</i>, width=><i>integer</i>, height=><i>integer</i>, x=><i>integer</i>, y=><i>integer</i></td> |
|---|
| 468 | <td valign="top">chop an image</td> |
|---|
| 469 | </tr> |
|---|
| 470 | |
|---|
| 471 | <tr> |
|---|
| 472 | <td valign="top">Clip</td> |
|---|
| 473 | <td valign="top">id=><i>name</i>, inside=><i>{true, false}</i>,</td> |
|---|
| 474 | <td valign="top">apply along a named path from the 8BIM profile.</td> |
|---|
| 475 | </tr> |
|---|
| 476 | |
|---|
| 477 | <tr> |
|---|
| 478 | <td valign="top">ClipMask</td> |
|---|
| 479 | <td valign="top">mask=><i>image-handle</i></td> |
|---|
| 480 | <td valign="top">clip image as defined by the image mask</td> |
|---|
| 481 | </tr> |
|---|
| 482 | |
|---|
| 483 | <tr> |
|---|
| 484 | <td valign="top">Clut</td> |
|---|
| 485 | <td valign="top">image=><i>image-handle</i>, channel=>{Red, Cyan, Green, Magenta, Blue, Yellow, Opacity, Black, or All}</td> |
|---|
| 486 | <td valign="top">apply a color lookup table to an image sequence</td> |
|---|
| 487 | </tr> |
|---|
| 488 | |
|---|
| 489 | <tr> |
|---|
| 490 | <td valign="top">Coalesce</td> |
|---|
| 491 | <td valign="top"><br /></td> |
|---|
| 492 | <td valign="top">merge a sequence of images</td> |
|---|
| 493 | </tr> |
|---|
| 494 | |
|---|
| 495 | <tr> |
|---|
| 496 | <td valign="top">Colorize</td> |
|---|
| 497 | <td valign="top">fill=><i><a href="../www/color.html">color name</a></i>, opacity=><i>string</i></td> |
|---|
| 498 | <td valign="top">colorize the image with the fill color</td> |
|---|
| 499 | </tr> |
|---|
| 500 | |
|---|
| 501 | <tr> |
|---|
| 502 | <td valign="top">Comment</td> |
|---|
| 503 | <td valign="top">string</td> |
|---|
| 504 | <td valign="top">add a comment to your image</td> |
|---|
| 505 | </tr> |
|---|
| 506 | |
|---|
| 507 | <tr> |
|---|
| 508 | <td valign="top">Compare</td> |
|---|
| 509 | <td valign="top">image=><i>image-handle</i></td> |
|---|
| 510 | <td valign="top">compare image to a reference image</td> |
|---|
| 511 | </tr> |
|---|
| 512 | |
|---|
| 513 | <tr> |
|---|
| 514 | <td valign="top">CompareLayers</td> |
|---|
| 515 | <td valign="top">method=>{any, clear, overlay}</td> |
|---|
| 516 | <td valign="top">compares each image with the next in a sequence and returns the maximum bounding region of any pixel differences it discovers.</td> |
|---|
| 517 | </tr> |
|---|
| 518 | |
|---|
| 519 | <tr> |
|---|
| 520 | <td valign="top">Composite</td> |
|---|
| 521 | <td valign="top">image=><i>image-handle</i>, compose=>{Undefined, Add, Atop, Blend, Bumpmap, Clear, ColorBurn, ColorDodge, Colorize, CopyBlack, CopyBlue, CopyCyan, CopyGreen, Copy, CopyMagenta, CopyOpacity, CopyRed, CopyYellow, Darken, Dst, Difference, Displace, Dissolve, DstAtop, DstIn, DstOut, DstOver, Dst, Exclusion, HardLight, Hue, In, Lighten, Luminize, Minus, Modulate, Multiply, None, Out, Overlay, Over, Plus, ReplaceCompositeOp, Saturate, Screen, SoftLight, Src, SrcAtop, SrcIn, SrcOut, SrcOver, Src, Subtract, Threshold, Xor }, mask=><i>image-handle</i>, geometry=><i>geometry</i>, x=><i>integer</i>, y=><i>integer</i>, gravity=>{NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast}, opacity=><i>integer</i>, tile=>{True, False}, rotate=><i>double</i>, color=><i><a href="../www/color.html">color name</a></i>, blend=><i>geometry</i>, interpolate=>{undefined, average, bicubic, bilinear, filter, integer, mesh, nearest-neighbor, spline}</td> |
|---|
| 522 | <td valign="top">composite one image onto another</td> |
|---|
| 523 | </tr> |
|---|
| 524 | |
|---|
| 525 | <tr> |
|---|
| 526 | <td valign="top">Contrast</td> |
|---|
| 527 | <td valign="top">sharpen=>{True, False}</td> |
|---|
| 528 | <td valign="top">enhance or reduce the image contrast</td> |
|---|
| 529 | </tr> |
|---|
| 530 | |
|---|
| 531 | <tr> |
|---|
| 532 | <td valign="top">ContrastStretch</td> |
|---|
| 533 | <td valign="top">levels=><i>string</i>, 'black-point'=><i>double</i>, 'white-point'=><i>double</i>, channel=>{Red, Cyan, Green, Magenta, Blue, Yellow, Opacity, Black, or All}</td> |
|---|
| 534 | <td valign="top">improve the contrast in an image by `stretching' the range of intensity values</td> |
|---|
| 535 | </tr> |
|---|
| 536 | |
|---|
| 537 | <tr> |
|---|
| 538 | <td valign="top">Convolve</td> |
|---|
| 539 | <td valign="top">coefficients=><i>array of float values</i>, channel=>{All, Default, Alpha, Black, Blue, Cyan, Gray, Green, Index, Magenta, Opacity, Red, Yellow}, bias=>;<i>double</i></td> |
|---|
| 540 | <td valign="top">apply a convolution kernel to the image. Given a kernel <i>order</i> , you would supply <i>order*order</i> float values (e.g. 3x3 implies 9 values).</td> |
|---|
| 541 | </tr> |
|---|
| 542 | |
|---|
| 543 | <tr> |
|---|
| 544 | <td valign="top">Crop</td> |
|---|
| 545 | |
|---|