Name
Read( ) — read one or more image files
Synopsis
$image->Read(list
)
The Read( )
method reads an image or
an image sequence from the specified files (of any supported format)
or reads in a new “blank” image with a background
color. When an image is read, its file format is determined by its
magic number, which is the first field in the image header. To force a
specific image format, use the name of the format followed by a colon
before the filename string. Filenames ending with a
.gz
or .Z
extension (on a
Unix system) will be first decompressed using uncompress or gunzip.
The list can be a list of strings in any of the following forms:
$image->Read('gif:foo.gif') # Read a single GIF file into $image $image->Read('foo.gif', 'gumbar.jpg'); # Read two images into $image object # guessing the file format # from their magic numbers $image->Read('*.gif'); # Read all of the .gif files in the # current directory into $image open(IMAGE, "image.gif"); # Open the file for reading binmode IMAGE; # Make sure we're in binary mode $image->Read(file=>\*IMAGE); # Read from open Perl filehandle
Certain file formats allow more than one image to be contained in the same file (see Table 5.1). Each image in a sequence still may be accessed individually. For example, to set the transparent color of only the first image in a sequence to white, use:
$image->[0]->Transparent('#FFFFFF');
You can also read in specific “subimages” of a multi-resolution file format such as Photo CD or MPEG. Accessing subimages ...
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.