Image::Size

A Perl module that can read the dimensions of an image in several popular formats.
Download

Image::Size Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Randy J. Ray
  • Publisher web site:
  • http://search.cpan.org/~rjray/WebService-ISBNDB-0.34/lib/WebService/ISBNDB/API/Subjects.pm

Image::Size Tags


Image::Size Description

A Perl module that can read the dimensions of an image in several popular formats. Image::Size is a Perl module that can read the dimensions of an image in several popular formats.SYNOPSIS use Image::Size; # Get the size of globe.gif ($globe_x, $globe_y) = imgsize("globe.gif"); # Assume X=60 and Y=40 for remaining examples use Image::Size 'html_imgsize'; # Get the size as 'width="X" height="Y"' for HTML generation $size = html_imgsize("globe.gif"); # $size == 'width="60" height="40"' use Image::Size 'attr_imgsize'; # Get the size as a list passable to routines in CGI.pm @attrs = attr_imgsize("globe.gif"); # @attrs == ('-width', 60, '-height', 40) use Image::Size; # Get the size of an in-memory buffer ($buf_x, $buf_y) = imgsize($buf); # Assuming that $buf was the data, imgsize() needed a reference to a scalarThe Image::Size library is based upon the wwwis script written by Alex Knowles (alex@ed.ac.uk), a tool to examine HTML and add 'width' and 'height' 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 '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 dually suited to both HTML and XHTML.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 ("-width", X, "-height", Y). If the underlying call to imgsize fails, undef is returned.By default, only imgsize() is exported. Any one or combination of the three may be explicitly imported, or all three may be with the tag :all.Input TypesThe sort of data passed as stream can be one of three forms:stringIf 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 referenceIf the passed-in stream is a scalar reference, it is interpreted as pointing to an in-memory buffer containing the image data. # Assume that &read_data gets data somewhere (WWW, etc.) $img = &read_data; ($x, $y, $id) = imgsize($img); # $x and $y are dimensions, $id is the type of the imageOpen file handleThe third option is to pass in an open filehandle (such as an object of the IO::File class, for example) that has already been associated with 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. Requirements: · Perl What's New in This Release: · Compress::Zlib is now optional. · The distribution was refactored. · The cache was made visible outside the lexical scope of the module to make it possible to use with IPC.


Image::Size Related Software