This software module implemented in Perl enables reading of the dimensional details of various image formats. It is compatible with popular image formats and allows efficient access to image attributes. The module can seamlessly integrate into different software applications.
The module provides three interfaces: imgsize(), html_imgsize(), and attr_imgsize(). By default, only imgsize() is exported; the other interfaces must be imported. imgsize() returns a three-item list of the X and Y dimensions and image type of stream. If an error is encountered, undef is returned for the first two elements, and an error string is returned for the third.
html_imgsize() returns the width and height of stream pre-formatted as a single string 'width="X" height="Y"' suitable for addition into generated HTML IMG tags. If the underlying call to imgsize fails, undef is returned. The format returned is suitable for both HTML and XHTML.
attr_imgsize() 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. If the underlying call to imgsize fails, undef is returned.
The sort of data passed as stream can be one of three forms: string, scalar reference, or open file handle. If an ordinary scalar (string) is passed, it is assumed to be a file name and opened (if found) as the source of data. If the passed-in stream is a scalar reference, it is interpreted as pointing to an in-memory buffer containing the image data. If an open file handle is passed in, the file pointer will necessarily move but will be restored to its original position before subroutine end.
Overall, Image::Size offers a straightforward and efficient solution for determining the dimensions of an image in various formats. Its multiple interfaces make it a versatile tool for generating HTML or manipulating named parameters, and its internal caching ensures optimal performance.
Version 3.2: N/A