DESCRIPTION

The Image::Size library is based upon the wwwis script written by Alex Knowles (alex@ed.ac.uk), a tool to examine HTML and add HEIGHT and WIDTH parameters to image tags. The sizes are cached internally based on file name, so multiple calls on the same file name (such as images used in bulleted lists, for example) do not result in repeated computations.

Image::Size provides three interfaces for possible import:

imgsize(stream)

Returns a three-item list of the X and Y dimensions (width and height, in that order) and image type of stream. Errors are noted by undefined (undef) values for the first two elements, and an error string in the third. The third element can be (and usually is) ignored, but is useful when sizing data whose type is unknown.

html_imgsize(stream)

Returns the width and height (X and Y) of stream pre-formatted as a single string "HEIGHT=X WIDTH=Y" suitable for addition into generated HTML IMG tags. If the underlying call to imgsize fails, undef is returned.

attr_imgsize(stream)

Returns the width and height of stream as part of a 4-element list useful for routines that use hash tables for the manipulation of named parameters, such as the Tk or CGI libraries. A typical return value looks like ("-HEIGHT", Y, "-WIDTH", X). If the underlying call to imgsize fails, undef is returned.

By default, only imgsize() is imported. Any one or combination of the three may be imported, or all three may be with the tag :all.

Input Types

The sort of data passed as stream can be one of three forms:

string

If an ordinary scalar (string) is passed, it is assumed to be a file name (either absolute or relative to the current working directory of the process) and is searched for and opened (if found) as the source of data. Possible error messages (see DIAGNOSTICS below) may include file-access problems.

scalar reference

If the passed-in stream is a scalar reference, it is interpreted as pointing to an in-memory buffer containing the image data.

The third option is to pass in an object of the IO::File class that has already been instantiated on the target image file. The file pointer will necessarily move, but will be restored to its original position before subroutine end.

# $fh was passed in, is IO::File reference:
($x, $y, $id) = imgsize($fh);
# Same as calling with filename, but more abstract.

Recognizd Formats

Image::Size understands and sizes data in the following formats:

GIF

JPG

XBM

XPM

PPM family (PPM/PGM/PBM)

PNG

TIF

BMP

When using the imgsize interface, there is a third, unused value returned if the programmer wishes to save and examine it. This value is the three- letter identity of the data type. This is useful when operating on open file handles or in-memory data, where the type is as unknown as the size. The two support routines ignore this third return value, so those wishing to use it must use the base imgsize routine.

DIAGNOSTICS

The base routine, imgsize, returns undef as the first value in its list when an error has occured. The third element contains a descriptive error message.

The other two routines simply return undef in the case of error.

CAVEATS

This will reliably work on perl 5.002 or newer. Perl versions prior to 5.003 do not have the IO::File module by default, which this module requires. You will have to retrieve and install it, or upgrade to 5.003 (or later), in which it is included as part of the core.

Caching of size data can only be done on inputs that are file names. Open file handles and scalar references cannot be reliably transformed into a unique key for the table of cache data. Buffers could be cached using the MD5 module, and perhaps in the future I will make that an option. I do not, however, wish to lengthen the dependancy list by another item at this time.

SEE ALSO

http://www.tardis.ed.ac.uk/~ark/wwwis/ for a description of wwwis and how to obtain it.