Contents |
Introduction |
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 MogrifyMagick, or use L-systems to create images of plants using mathematical constructs, and finally navigate through collections of thumbnail images and select the image to view with the WebMagick Image Navigator.
You can try PerlMagick from your Web browser at the ImageMagick Studio. Or, you can see examples of select PerlMagick functions.
An object-oriented Python interface to ImageMagick is also available, see PythonMagick.
Installation |
ImageMagick must already be installed on your system. Next, get the PerlMagick distribution and unpack it as shown below:
gunzip -c PerlMagick-4.29.tar.gz | tar -xvf - cd PerlMagickNext, edit Makefile.PL and change LIBS and INC to include the appropriate path information to the required libMagick 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:
perl Makefile.PL make make installFor Unix, you typically need to be root to install the software. There are ways around this. Consult the Perl manual pages for more information.
Windows NT / Windows 95
ImageMagick must already be installed on your system. Also, the ImageMagick source distribution for Windows NT is required. You must also have the nmake from the Visual C++ or J++ development environment. Copy \bin\IMagick.dll and \bin\X11.dll to a directory in your dynamic load path such as c:\perl\site\5.00502. Next, type
cd PerlMagick copy Makefile.nt Makefile.PL perl Makefile.PL nmake nmake installRunning the Regression Tests
To verify a correct installation, type
make testUse nmake test under Windows. There are ao few demonstration scripts available to exercise many of the functions PerlMagick can perform. Type
cd demo makeYou are now ready to utilize the PerlMagick methods from within your Perl scripts.
Overview |
use Image::Magick; $image=Image::Magick->new;The new method takes the same parameters as SetAttribute. For example,
$image=Image::Magick->new(size=>'384x256');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 Read or Write an Image. See Set an Image Attribute for methods that affect the way an image is read or written. Refer to Manipulate an Image for a list of methods to transform an image. Get an Image Attribute describes how to retrieve an attribute for an image. Refer to Create an Image Montage 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 Miscellaneous Methods for a list of these methods.
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 undef:
undef $image;To delete all the images but retain the Image::Magick object use
undef @$image;and finally, to delete a single image from a multi-image sequence, use
undef $image->[x];The next section illustrates how to use various PerlMagick methods to manipulate an image sequence.
Some of the PerlMagick methods require external programs such as Ghostscript. This may require an explicit path in your PATH environment variable to work properly. For example,
$ENV{PATH}='/bin:/usr/bin:/usr/local/bin';
Example Script |
#!/usr/local/bin/perl use Image::Magick; my($image, $x); $image = Image::Magick->new; $x = $image->Read('girl.gif', 'logo.gif', 'rose.gif'); warn "$x" if "$x"; $x = $image->Crop(geometry=>'100x100"+1"00"+1"00'); warn "$x" if "$x"; $x = $image->Write('x.gif'); warn "$x" if "$x";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:
#!/usr/local/bin/perl use Image::Magick; my($image, $p, $q); $image = new Image::Magick; $image->Read('x1.gif'); $image->Read('j*.jpg'); $image->Read('k.miff[1, 5, 3]'); $image->Contrast; for ($x = 0; $image->[x]; $x++) { $image->[x]->Frame('100x200') if $image->[x]->Get('magick') eq 'GIF'; undef $image->[x] if $image->[x]->Get('columns') < 100; } $p = $image->[1]; $p->Draw(pen=>'red', primitive=>'rectangle', points=>20,20 100,100'); $q = $p->Montage(); undef $image; $q->Write('x.miff');Suppose you want to start out with a 100 by 100 pixel white canvas with a red pixel in the center. Try
$image = Image::Magick->new; $image->Set(size=>'100x100'); $image->ReadImage('xc:white'); $image->Set('pixel[49,49]'=>'red');Or suppose you want to convert your color image to grayscale:
$image->Quantize(colorspace=>'gray');Here we annotate an image with a Taipai TrueType font:
$text = "\\0x17ef\\0x30ec\\0x25ec\\0x23ef\\0x17ec"; $image->Annotate(font=>'@kai.ttf', pointsize=>40, pen=>'green', text=>$text);Other clever things you can do with PerlMagick objects include
$i = $#$p"+1"; # return the number of images associated with object p push(@$q, @$p); # push the images from object p onto object q undef @$p; # delete the images but not the object p
Read or Write an Image |
Method | Parameters | Return Value | Description |
---|---|---|---|
Read | one or more filenames | the number of images read | read an image or image sequence |
Write | filename | the number of images written | write an image or image sequence |
Display | server name | the number of images displayed | display the image or image sequence to an X server |
Animate | server name | the number of images animated | animate image sequence to an X server |
For convenience, methods Write, Display, and Animate can take any parameter that SetAttribute knows about. For example,
$image->Write(filename=>'image.png', compress=>'None');Use - as the filename to method Read to read from standard in or to method Write to write to standard out:
binmode STDOUT; $image->Write('gif:-');To read an image in the GIF format from a PERL filehandle, use:
$image = Image::Magick->new(magick=>'GIF'); open(DATA, 'image.gif'); $image->Read(file=>DATA); close(DATA);To write an image in the PNG format to a PERL filehandle, use:
$filename = "image.png"; open(DATA, ">$filename"); $image->Write(file=>DATA, filename=>$filename); close(DATA);You can optionally add Image to any method name. For example, ReadImage is an alias for method Read.
Manipulate an Image |
$image->Crop(geometry=>'100x100"+1"0+20'); $image->[x]->Frame("100x200");And here is a list of other image manipulation methods you can call:
Method | Parameters | Description |
---|---|---|
AddNoise | noise=>{Uniform, Gaussian, Multiplicative, Impulse, Laplacian, Poisson} | add noise to an image |
Annotate | text=>string, font=>string, pointsize=>integer, density=>geometry, box=>colorname, pen=>colorname, geometry=>geometry, server=>{string, @filename}, gravity=>{NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast}, x=>integer, y=>integer, degrees=>double | annotate an image with text. |
Blur | factor=>percentage | blurs an image |
Border | geometry=>geometry, width=>integer, height=>integer, color=colorname | surround the image with a border of color |
Charcoal | factor=>percentage | simulate a charcoal drawing |
Chop | geometry=>geometry, width=>integer, height=>integer, x=>integer, y=>integer | chop an image |
Clone | make a copy an image | |
Coalesce | merge a sequence of images | |
ColorFloodfill | geometry=>geometry, x=>integer, y=>integer, pen=colorname, bordercolor=colorname | changes the color value of any pixel that matches the color of the target pixel and is a neighbor. If you specify a border color, the color value is changed for any neighbor pixel that is not that color. |
Colorize | color=>colorname, pen=>colorname | colorize the image with the pen color |
Comment | string | add a comment to your image |
Composite | compose=>{Over, In, Out, Atop, Xor, Plus, Minus, Add, Subtract, Difference, Bumpmap, Replace, ReplaceRed, ReplaceGreen, ReplaceBlue, ReplaceMatte, Blend, Displace}, image=>image-handle, geometry=>geometry, x=>integer, y=>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 | |
Contrast | sharpen=>{True, False} | enhance or reduce the image contrast |
Crop | geometry=>geometry, width=>integer, height=>integer, x=>integer, y=>integer | crop an image |
CycleColormap | amount=>integer | displace image colormap by amount |
Deconstruct | break down an image sequence into constituent parts | |
Despeckle | reduce the speckles within an image | |
Draw | primitive={Point, Line, Rectangle, FillRectangle, Circle, FillCircle, Ellipse, FillEllipse, Polygon, FillPolygon, Color, Matte, Text, Image, @filename}, points=>string, method={Point, Replace, Floodfill, FillToBorder, Reset}, pen=>colorname, bordercolor=>colorname, linewidth=>integer, server=>string, | annotate an image with one or more graphic primitives |
Edge | factor=>percentage | detect edges within an image |
Emboss | emboss the image | |
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 the vertical direction | |
Flop | create a mirror image by reflecting the image scanlines in the horizontal direction | |
Frame | geometry=>geometry, width=>integer, height=>integer, inner=>integer, outer=>integer, color=>colorname | surround the image with an ornamental border |
Gamma | gamma=>double, red=>double, green=>double, blue=>double | gamma correct the image |
Implode | factor=>percentage | implode image pixels about the center |
Label | string | assign a label to an image |
Layer | layer={Red, Green, Blue, Matte} | extract a layer from the image |
Magnify | double the size of an image | |
Map | image=>image-handle, dither={True, False} | choose a particular set of colors from this image |
MatteFloodfill | geometry=>geometry, x=>integer, y=>integer, matte=integer, bordercolor=colorname | changes the matte value of any pixel that matches the color of the target pixel and is a neighbor. If you specify a border color, the matte value is changed for any neighbor pixel that is not that color. |
Minify | half the size of an image | |
Modulate | brightness=>double, saturation=>double, hue=>double | vary the brightness, saturation, and hue of an image |
Negate | gray=>{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 | |
OilPaint | radius=>integer | simulate an oil painting |
Opaque | color=>colorname, pen=>colorname | change this color to the pen color within the image |
Quantize | colors=>integer, colorspace=>{RGB, Gray, Transparent, OHTA, XYZ, YCbCr, YIQ, YPbPr, YUV, CMYK}, treedepth=> integer, dither=>{True, False}, measure_error=>{True, False}, global_colormap=>{True, False} | preferred number of colors in the image |
Raise | geometry=>geometry, width=>integer, height=>integer, x=>integer, y=>integer, raise=>{True, False} | lighten or darken image edges to create a 3-D effect |
ReduceNoise | add or reduce the noise in an image | |
Roll | geometry=>geometry, x=>integer, y=>integer | roll an image vertically or horizontally |
Rotate | degrees=>double, crop=>{True, False}, sharpen=>{True, False} | roll an image vertically or horizontally |
Sample | geometry=>geometry, width=>integer, height=>integer | scale image with pixel sampling |
Scale | geometry=>geometry, width=>integer, height=>integer | scale image to desired size |
Segment | colorspace=>{RGB, Gray, Transparent, OHTA, XYZ, YCbCr, YCC, YIQ, YPbPr, YUV, CMYK}, verbose={True, False}, cluster=>double, smooth=double | segment an image by analyzing the histograms of the color components and identifying units that are homogeneous |
Shade | geometry=>geometry, azimuth=>double, elevation=>double, color=>{true, false} | shade the image using a distant light source |
Sharpen | factor=>percentage | sharpen an image |
Shear | geometry=>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 | |
Solarize | factor=>percentage | negate all pixels above the threshold level |
Spread | amount=>integer | displace image pixels by a random amount |
Stereo | image=>image-handle | combines two images and produces a single image that is the composite of a left and right image of a stereo pair |
Stegano | image=>image-handle, offset=integer | hide a digital watermark within the image |
Swirl | degrees=>double | swirl image pixels about the center |
Texture | texture=>image-handle | name of texture to tile onto the image background |
Threshold | threshold=>integer | threshold the image |
Transform | crop=>geometry, geometry=>geometry, filter=>{Point, Box, Triangle, 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=>colorname | make this color transparent within the image |
Trim | remove edges that are the background color from the image | |
Wave | geometry=>geometry, amplitude=>double, wavelength=>double | alter an image along a sine wave |
Zoom | geometry=>geometry, width=>integer, height=>integer, filter=>{Point, Box, Triangle, Hermite, Hanning, Hamming, Blackman, Gaussian, Quadratic, Cubic, Catrom, Mitchell, Lanczos, Bessel, Sinc}, blur=>double | scale image to desired size. Specify blur > 1 for blurry or < 1 for sharp |
Note, that the geometry parameter is a short cut for the width and height parameters (e.g. geometry=>'106x80' is equivalent to width=>106, height=>80).
You can specify @filename in both Annotate and Draw. This reads the text or graphic primitive instructions from a file on disk. For example,
$image->Draw(pen=>'red', primitive=>'rectangle', points=>'20,20 100,100 40,40 200,200 60,60 300,300');Is eqivalent to
$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, 300The text parameter for methods, Annotate, Comment, Draw, and Label can include the image filename, type, width, height, or other image attribute by embedding these special format characters:
%b file size %d directory %e filename extension %f filename %h height %m magick %p page number %s scene number %t top of filename %w width %x x resolution %y y resolution \n newline \r carriage returnFor example,
text=>"%m:%f %wx%h"
You can optionally add Image to any method name. For example, TrimImage is an alias for method Trim.
Most of the attributes listed above have an analog in convert. See the documentation for a more detailed description of these attributes.
Set an Image Attribute |
$image->Set(dither=>'True'); $image->[$x]->Set(delay=>3);And here is a list of all the image attributes you can set:
Attribute | Values | Description |
---|---|---|
adjoin | {True, False} | join images into a single multi-image file |
antialias | {True, False} | remove pixel aliasing |
background | string | image background color |
blue_primary | x-value, y-value | chromaticity blue primary point (e.g. 0.15, 0.06) |
bordercolor | string | set the image border color |
colormap[i] | string | color name (e.g. red) or hex value (e.g. #ccc) at position i |
colorspace | {RGB, CMYK} | type of colorspace |
compress | None, BZip, Fax, Group4, JPEG, LZW, Runlength, Zip | type of image compression |
delay | integer | this many 1/100ths of a second\fP must expire before displaying the next image in a sequence |
density | geometry | vertical 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 |
display | string | specifies the X server to contact |
file | filehandle | set the image filehandle |
filename | string | set the image filename |
font | string | use this font when annotating the image with text |
fuzz | integer | colors within this distance are considered equal |
green_primary | x-value, y-value | chromaticity green primary point (e.g. 0.3, 0.6) |
interlace | {None, Line, Plane, Partition} | the type of interlacing scheme |
iterations | integer | add Netscape loop extension to your GIF animation |
loop | integer | add Netscape loop extension to your GIF animation |
magick | string | set the image format |
matte | {True, False} | True if the image has transparency |
mattecolor | string | set the image matte color |
monochrome | {True, False} | transform the image to black and white |
page | { Letter, Tabloid, Ledger, Legal, Statement, Executive, A3, A4, A5, B4, B5, Folio, Quarto, 10x14} or geometry | preferred size and location of an image canvas |
pen | color | color name (e.g. red) or hex value (e.g. #ccc) for annotating or changing opaque color |
pixel[x, y] | string | color name (e.g. red) or hex value (e.g. #ccc) at position (x, y) |
pointsize | integer | pointsize of the Postscript or TrueType font |
preview | { Rotate, Shear, Roll, Hue, Saturation, Brightness, Gamma,>
Transfer interrupted!speckle, ReduceNoise, AddNoise, Sharpen, Blur, Threshold, EdgeDetect, Spread, Solarize, Shade, Raise, Segment, Swirl, Implode, Wave, OilPaint, CharcoalDrawing, JPEG} |
type of preview for the Preview image format |
quality | integer | JPEG/MIFF/PNG compression level |
red_primary | x-value, y-value | chromaticity red primary point (e.g. 0.64, 0.33) |
rendering_intent | {Undefined, Saturation, Perceptual, Absolute, Relative} | the type of rendering intent |
scene | integer | image scene number |
subimage | integer | subimage of an image sequence |
subrange | integer | number of images relative to the base image |
server | string | specifies the X server to contact |
size | string | width and height of a raw image |
tile | string | tile name |
texture | string | name 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 |
view | string | FlashPix viewing parameters |
white_point | x-value, y-value | chromaticity white point (e.g. 0.3127, 0.329) |
Note, that the geometry parameter is a short cut for the width and height parameters (e.g. geometry=>'106x80' is equivalent to width=>106, height=>80).
SetAttribute is an alias for method Set.
Most of the attributes listed above have an analog in convert. See the documentation for a more detailed description of these attributes.
Get an Image Attribute |
($a, $b, $c) = $image->Get('colorspace', 'magick', 'adjoin'); $width = $image->[3]->Get('columns');In addition to all the attributes listed in Set an Image Attribute, you can get these additional attributes:
Attribute | Values | Description |
---|---|---|
base_columns | integer | base image width (before transformations) |
base_filename | string | base image filename (before transformations) |
base_rows | integer | base image height (before transformations) |
class | {Direct, Pseudo} | image class |
colors | integer | number of unique colors in the image |
comment | string | image comment |
columns | integer | image width |
depth | integer | image depth |
directory | string | tile names from within an image montage |
filesize | integer | number of bytes of the image on disk |
format | string | get the descriptive image format |
gamma | double | gamma level of the image |
geometry | string | image geometry |
height | integer | the number of rows or height of an image |
label | string | image label |
mean | double | the mean error per pixel computed when an image is color reduced |
montage | geometry | tile size and offset within an image montage |
normalized_max | double | the normalized max error per pixel computed when an image is color reduced |
normalized_mean | double | the normalized mean error per pixel computed when an image is color reduced |
packetsize | integer | the number of bytes in each pixel packet |
packets | integer | the number of runlength-encoded packets in the image |
rows | integer | the number of rows or height of an image |
signature | string | MD5 signature associated with the image |
tainted | {True, False} | True if the image has been modified |
text | string | any text associated with the image |
type | {Bilevel, Grayscale, Palette, TrueColor, MatteType, ColorSeparation } | image type |
width | integer | the number of columns or width of an image |
x-resolution | integer | x resolution of the image |
y-resolution | integer | y resolution of the image |
GetAttribute is an alias for method Get.
Most of the attributes listed above have an analog in convert. See the documentation for a more detailed description of these attributes.
Create an Image Montage |
$image->Montage(geometry=>'160x160', tile=>'2x2', texture=>'granite:');And here is a list of Montage parameters you can set:
Parameter | Values | Description |
---|---|---|
background | color | X11 color name |
borderwidth | integer | image border width |
compose | {Over, In, Out, Atop, Xor, Plus, Minus, Add, Subtract, Difference, Bumpmap, Replace, MatteReplace, Mask, Blend, Displace} | composite operator |
filename | string | name of montage image |
font | string | X11 font name |
frame | geometry | surround the image with an ornamental border |
geometry | geometry | preferred 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 |
label | string | assign a label to an image |
mode | {Frame, Unframe, Concatenate} | thumbnail framing options |
pen | string | color for annotation text |
pointsize | integer | pointsize of the Postscript or TrueType font |
shadow | {True, False} | add a shadow beneath a tile to simulate depth |
texture | string | name of texture to tile onto the image background |
tile | geometry | number of tiles per row and column |
title | string | assign a title to the image montage |
transparent | string | make this color transparent within the image |
Note, that the geometry parameter is a short cut for the width and height parameters (e.g. geometry=>'106x80' is equivalent to width=>106, height=>80).
MontageImage is an alias for method Montage.
Most of the attributes listed above have an analog in montage. See the documentation for a more detailed description of these attributes.
Miscellaneous Methods |
$x = $image->Append(stack=>{true,false});appends all the images associated with object $image. All the input images must have the same width or height. Images of the same width are stacked top-to-bottom. Images of the same height are stacked left-to-right. If the stack parameter is false, rectangular images are stacked left-to-right otherwise top-to-bottom.
$x = $image->Average();averages all the images associated with object $image.
$x = $image->Morph(frames=>integer);where frames is the number of in-between images to generate. The default is 1.
Method Mogrify is a single entry point for the image manipulation methods (Manipulate an Image). The parameters are the name of a method followed by any parameters the method may require. For example, these calls are equivalent:
$image->Crop('340x256+0+0'); $image->Mogrify('crop', '340x256+0+0');Method MogrifyRegion applies a transform to a region of the image. It is similiar to Mogrify but begins with the region geometry. For example, suppose you want to brighten a 100x100 region of your image at location (40, 50):
$image->MogrifyRegion('100x100+40+50', 'modulate', brightness=>50);
$p = $image->Clone();copies all the images from object $q to $p. Use this method for multi-image sequences. PerlMagick transparently creates a linked list from an image array. If two locations in the array point to the same object, the linked list goes into an infinite loop and your script will run forever until interrupted. Instead of
push(@$images, $image); push(@$images, $image); # warning duplicate objectuse cloning to prevent an infinite loop:
push(@$images, $image); $clone=$image->Clone(); push(@$images, $clone); # same image but different objectPing accepts one or more image file names and returns their respective width, height, size in bytes, and format (e.g. GIF, JPEG, etc.). For example,
($width, $height, $size, $format) = split(',', $image->Ping('logo.gif'));This is a more efficient and less memory intensive way to query if an image exists and what its characteristics are. Note, only information about the first image in a multi-frame image file is returned.
You can optionally add Image to any method name above. For example, PingImage is an alias for method Ping.
Use RemoteCommand to send a command to an already running display or animate application. The only parameter is the name of the image file to display or animate.
Finally, for convenience, method QueryColor accepts one or more color names or hex value and returns their respective red, green, and blue color values:
($red, $green, $blue) = split(', ', $image->QueryColor('cyan')); ($red, $green, $blue) = split(', ', $image->QueryColor('#716bae'));
Handling Errors |
$x = $image->Read(...); warn "$x" if "$x"; # print the error message $x =~ /(\d+)/; print $1; # print the error number print 0+$x; # print the number of images read
$x = $image->Crop(...); warn "$x" if "$x"; # print the error message $x =~ /(\d+)/; print $1; # print the error number
$x = $image->Montage(...); warn "$x" if !ref($x); # print the error message $x =~ /(\d+)/; print $1; # print the error numberHere is an example error message:
Error 400: Memory allocation failedBelow is a list of error and warning codes:
Code | Mnemonic | Description |
---|---|---|
0 | Success | method completed without an error or warning |
300 | ResourceLimitWarning | a program resource is exhausted (e.g. not enough memory) |
305 | XServerWarning | an X resource is unavailable |
310 | OptionWarning | a command-line option was malformed |
315 | DelegateWarning | an ImageMagick delegate returned a warning |
320 | MissingDelegateWarning | the image type can not be read or written because the appropriate Delegate is missing |
325 | CorruptImageWarning | the image file may be corrupt |
330 | FileOpenWarning | the image file could not be opened |
400 | ResourceLimitError | a program resource is exhausted (e.g. not enough memory) |
405 | XServerError | an X resource is unavailable |
410 | OptionError | a command-line option was malformed |
415 | DelegateError | an ImageMagick delegate returned a warning |
420 | MissingDelegateError | the image type can not be read or written because the appropriate Delegate is missing |
425 | CorruptImageError | the image file may be corrupt |
430 | FileOpenError | the image file could not be opened |
The following illustrates how you can use a numeric status code:
$x = $image->Read('rose.gif'); $x =~ /(\d+)/; die "unable to continue" if ($1 == ResourceLimitError);Back to Contents
Working with Blobs |
Method | Parameters | Return Value | Description |
---|---|---|---|
ImageToBlob | any image attribute | an array of image data in the respective image format | convert an image or image sequence to an array of blobs |
BlobToImage | one or more blobs | the number of blobs converted to an image | convert one or more blobs to an image |
ImageToBlob returns the image data in their respective formats. You can then print it, save it to an ODBC database, write it to a file, or pipe it to a display program:
@blobs = $image->ImageToBlob(); open(DISPLAY,"| display -") || die; binmode DISPLAY; print DISPLAY $blobs[0]; close DISPLAY;Method BlobToImage returns an image or image sequence converted from the supplied blob:
$blob=$db->GetImage(); $image=Image::Magick->new(magick=>'jpg'); $image->BlobToImage($blob);
Copyright |