Reading and Writing Images

The Read( ) and Write( ) methods allow you to get images into or out of an image object. Internally, images are stored in a flexible abstract data structure that may be written to any of the many different supported file formats (see Appendix C for a complete list of file formats and prefixes). The default write format is in the MIFF format (Magick Image File Format), which was created specifically for storing ImageMagick image data. If you are interested in the full specifications for the MIFF format, they are available on the CD-ROM that comes with O’Reilly’s The Encyclopedia of Graphics File Formats.

While writing, you can set any of the attributes described in the section Retrieving and Setting File Information by sending it as a parameter to Write( ). For example:

$image->Write(filename => 'xc:white', compress => 'Zip');

If you are using an X Server, you can display an image directly from Perl. The Display( ) and Animate( ) methods may be used to send the image directly to the display or animate programs described at the beginning of this chapter.

Get Perl Graphics Programming 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.