Name

Write( ) — write one or more image files

Synopsis

Write( ) allows you to write the data for a single image or a sequence to a file or standard output. When using PerlMagick in CGI applications, you must use a hyphen (-) as the filename to write to standard output. Calling Write( ) without a specified filename will write to the file indicated by the image’s filename attribute. If there is a writing problem, Write( ) returns the number of images successfully written. Error checking may be done as for the Read( ) operation described earlier.

If you have read a sequence of images into an Image::Magick object, you can write out the entire sequence as a single file if your output format supports multiple images, or you can write individual scenes from the sequence.

Some examples:

$button->Write('jpeg:button.jpg'); # write to button.jpg as a JPEG

$image->Write('gif:-');            # No this isn't a smiley with half 
                                   # a moustache; the - means write to STDOUT

$image->Write(file=>IMAGE);        # Write to an open Perl filehandle 

$images->[0]->Write('foobar.gif'); # write only the first image in a sequence

$image->Read('foo.gif');           # If this is the only read...
$image->Write();                   # ...this will write to foo.gif

Instead of writing your image to a file, you can instead display it to any X11 screen. Use Display( ) to display one image at a time to the screen and Animate( ) to display an image sequence.

Get Programming Web Graphics with Perl and GNU Softwar now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.