.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. | will give a .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' .\" expand to `' in nroff, nothing in troff, for use with C<>. .tr \(*W-|\(bv\*(Tr .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Image::Size 3" .TH Image::Size 3 "2008-01-01" "perl v5.8.8" "User Contributed Perl Documentation" .SH "NAME" Image::Size \- read the dimensions of an image in several popular formats .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 4 \& 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 .Ve .PP .Vb 4 \& 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"' .Ve .PP .Vb 4 \& 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) .Ve .PP .Vb 4 \& use Image::Size; \& # Get the size of an in-memory buffer \& ($buf_x, $buf_y) = imgsize(\e$buf); \& # Assuming that $buf was the data, imgsize() needed a reference to a scalar .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The \fBImage::Size\fR library is based upon the \f(CW\*(C`wwwis\*(C'\fR script written by Alex Knowles \fI(alex@ed.ac.uk)\fR, a tool to examine \s-1HTML\s0 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. .PP \&\fBImage::Size\fR provides three interfaces for possible import: .IP "imgsize(\fIstream\fR)" 4 .IX Item "imgsize(stream)" Returns a three-item list of the X and Y dimensions (width and height, in that order) and image type of \fIstream\fR. Errors are noted by undefined (\fBundef\fR) 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. .IP "html_imgsize(\fIstream\fR)" 4 .IX Item "html_imgsize(stream)" Returns the width and height (X and Y) of \fIstream\fR pre-formatted as a single string \f(CW'width="X" height="Y"'\fR suitable for addition into generated \s-1HTML\s0 \s-1IMG\s0 tags. If the underlying call to \f(CW\*(C`imgsize\*(C'\fR fails, \fBundef\fR is returned. The format returned is dually suited to both \s-1HTML\s0 and \s-1XHTML\s0. .IP "attr_imgsize(\fIstream\fR)" 4 .IX Item "attr_imgsize(stream)" Returns the width and height of \fIstream\fR 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 \s-1CGI\s0 libraries. A typical return value looks like \&\f(CW\*(C`("\-width", X, "\-height", Y)\*(C'\fR. If the underlying call to \f(CW\*(C`imgsize\*(C'\fR fails, \&\fBundef\fR is returned. .PP By default, only \f(CW\*(C`imgsize()\*(C'\fR is exported. Any one or combination of the three may be explicitly imported, or all three may be with the tag \fB:all\fR. .Sh "Input Types" .IX Subsection "Input Types" The sort of data passed as \fIstream\fR can be one of three forms: .IP "string" 4 .IX Item "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 \s-1DIAGNOSTICS\s0 below) may include file-access problems. .IP "scalar reference" 4 .IX Item "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. .Sp .Vb 4 \& # Assume that &read_data gets data somewhere (WWW, etc.) \& $img = &read_data; \& ($x, $y, $id) = imgsize(\e$img); \& # $x and $y are dimensions, $id is the type of the image .Ve .IP "Open file handle" 4 .IX Item "Open file handle" The third option is to pass in an open filehandle (such as an object of the \f(CW\*(C`IO::File\*(C'\fR 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. .Sp .Vb 3 \& # $fh was passed in, is IO::File reference: \& ($x, $y, $id) = imgsize($fh); \& # Same as calling with filename, but more abstract. .Ve .Sh "Recognized Formats" .IX Subsection "Recognized Formats" Image::Size natively understands and sizes data in the following formats: .IP "\s-1GIF\s0" 4 .IX Item "GIF" .PD 0 .IP "\s-1JPG\s0" 4 .IX Item "JPG" .IP "\s-1XBM\s0" 4 .IX Item "XBM" .IP "\s-1XPM\s0" 4 .IX Item "XPM" .IP "\s-1PPM\s0 family (\s-1PPM/PGM/PBM\s0)" 4 .IX Item "PPM family (PPM/PGM/PBM)" .IP "\s-1XV\s0 thumbnails" 4 .IX Item "XV thumbnails" .IP "\s-1PNG\s0" 4 .IX Item "PNG" .IP "\s-1MNG\s0" 4 .IX Item "MNG" .IP "\s-1TIF\s0" 4 .IX Item "TIF" .IP "\s-1BMP\s0" 4 .IX Item "BMP" .IP "\s-1PSD\s0 (Adobe PhotoShop)" 4 .IX Item "PSD (Adobe PhotoShop)" .IP "\s-1SWF\s0 (ShockWave/Flash)" 4 .IX Item "SWF (ShockWave/Flash)" .IP "\s-1CWS\s0 (FlashMX, compressed \s-1SWF\s0, Flash 6)" 4 .IX Item "CWS (FlashMX, compressed SWF, Flash 6)" .IP "\s-1PCD\s0 (Kodak PhotoCD, see notes below)" 4 .IX Item "PCD (Kodak PhotoCD, see notes below)" .PD .PP Additionally, if the \fBImage::Magick\fR module is present, the file types supported by it are also supported by Image::Size. See also \*(L"\s-1CAVEATS\s0\*(R". .PP When using the \f(CW\*(C`imgsize\*(C'\fR interface, there is a third, unused value returned if the programmer wishes to save and examine it. This value is the identity of the data type, expressed as a 2\-3 letter abbreviation as listed above. 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 \f(CW\*(C`imgsize\*(C'\fR routine. .PP Note that when the \fBImage::Magick\fR fallback is used (for all non-natively supported files), the data type identity comes directly from the 'format' parameter reported by \fBImage::Magick\fR, so it may not meet the 2\-3 letter abbreviation format. For example, a \s-1WBMP\s0 file might be reported as \&'Wireless Bitmap (level 0) image' in this case. .ie n .Sh "Information Cacheing and $NO_CACHE" .el .Sh "Information Cacheing and \f(CW$NO_CACHE\fP" .IX Subsection "Information Cacheing and $NO_CACHE" When a filename is passed to any of the sizing routines, the default behavior of the library is to cache the resulting information. The modification-time of the file is also recorded, to determine whether the cache should be purged and updated. This was originally added due to the fact that a number of \s-1CGI\s0 applications were using this library to generate attributes for pages that often used the same graphical element many times over. .PP However, the cacheing can lead to problems when the files are generated dynamically, at a rate that exceeds the resolution of the modification-time value on the filesystem. Thus, the optionally-importable control variable \&\f(CW$NO_CACHE\fR has been introduced. If this value is anything that evaluates to a non-false value (be that the value 1, any non-null string, etc.) then the cacheing is disabled until such time as the program re-enables it by setting the value to false. .PP The parameter \f(CW$NO_CACHE\fR may be imported as with the \fBimgsize\fR routine, and is also imported when using the import tag \fB\f(CB\*(C`:all\*(C'\fB\fR. If the programmer chooses not to import it, it is still accessible by the fully-qualified package name, \fB$Image::Size::NO_CACHE\fR. .Sh "Sizing PhotoCD Images" .IX Subsection "Sizing PhotoCD Images" With version 2.95, support for the Kodak PhotoCD image format is included. However, these image files are not quite like the others. One file is the source of the image in any of a range of pre-set resolutions (all with the same aspect ratio). Supporting this here is tricky, since there is nothing inherent in the file to limit it to a specific resolution. .PP The library addresses this by using a scale mapping, and requiring the user (you) to specify which scale is preferred for return. Like the \f(CW$NO_CACHE\fR setting described earlier, this is an importable scalar variable that may be used within the application that uses \fBImage::Size\fR. This parameter is called \&\f(CW$PCD_SCALE\fR, and is imported by the same name. It, too, is also imported when using the tag \fB\f(CB\*(C`:all\*(C'\fB\fR or may be referenced as \&\fB$Image::Size::PCD_SCALE\fR. .PP The parameter should be set to one of the following values: .PP .Vb 6 \& base/16 \& base/4 \& base \& base4 \& base16 \& base64 .Ve .PP Note that not all PhotoCD disks will have included the \f(CW\*(C`base64\*(C'\fR resolution. The actual resolutions are not listed here, as they are constant and can be found in any documentation on the \s-1PCD\s0 format. The value of \&\f(CW$PCD_SCALE\fR is treated in a case-insensitive manner, so \f(CW\*(C`base\*(C'\fR is the same as \f(CW\*(C`Base\*(C'\fR or \f(CW\*(C`BaSe\*(C'\fR. The default scale is set to \f(CW\*(C`base\*(C'\fR. .PP Also note that the library makes no effort to read enough of the \s-1PCD\s0 file to verify that the requested resolution is available. The point of this library is to read as little as necessary so as to operate efficiently. Thus, the only real difference to be found is in whether the orientation of the image is portrait or landscape. That is in fact all that the library extracts from the image file. .Sh "Controlling Behavior with \s-1GIF\s0 Images" .IX Subsection "Controlling Behavior with GIF Images" \&\s-1GIF\s0 images present a sort of unusual situation when it comes to reading size. Because GIFs can be a series of sub-images to be isplayed as an animated sequence, what part does the user want to get the size for? .PP When dealing with \s-1GIF\s0 files, the user may control the behavior by setting the global value \fB$Image::Size::GIF_BEHAVIOR\fR. Like the \s-1PCD\s0 setting, this may be imported when loading the library. Three values are recognized by the GIF-handling code: .IP "0" 4 This is the default value. When this value is chosen, the returned dimensions are those of the \*(L"screen\*(R". The \*(L"screen\*(R" is the display area that the \s-1GIF\s0 declares in the first data block of the file. No sub-images will be greater than this in size; if they are, the specification dictates that they be cropped to fit within the box. .Sp This is also the fastest method for sizing the \s-1GIF\s0, as it reads the least amount of data from the image stream. .IP "1" 4 .IX Item "1" If this value is set, then the size of the first sub-image within the \s-1GIF\s0 is returned. For plain (non\-animated) \s-1GIF\s0 files, this would be the same as the screen (though it doesn't have to be, strictly\-speaking). .Sp When the first image descriptor block is read, the code immediately returns, making this only slightly-less efficient than the previous setting. .IP "2" 4 .IX Item "2" If this value is chosen, then the code loops through all the sub-images of the animated \s-1GIF\s0, and returns the dimensions of the largest of them. .Sp This option requires that the full \s-1GIF\s0 image be read, in order to ensure that the largest is found. .PP Any value outside this range will produce an error in the \s-1GIF\s0 code before any image data is read. .PP The value of dimensions other than the view-port (\*(L"screen\*(R") is dubious. However, some users have asked for that functionality. .SH "DIAGNOSTICS" .IX Header "DIAGNOSTICS" The base routine, \f(CW\*(C`imgsize\*(C'\fR, returns \fBundef\fR as the first value in its list when an error has occured. The third element contains a descriptive error message. .PP The other two routines simply return \fBundef\fR in the case of error. .SH "MORE EXAMPLES" .IX Header "MORE EXAMPLES" The \fBattr_imgsize\fR interface is also well-suited to use with the Tk extension: .PP .Vb 1 \& $image = $widget->Photo(-file => $img_path, attr_imgsize($img_path)); .Ve .PP Since the \f(CW\*(C`Tk::Image\*(C'\fR classes use dashed option names as \f(CW\*(C`CGI\*(C'\fR does, no further translation is needed. .PP This package is also well-suited for use within an Apache web server context. File sizes are cached upon read (with a check against the modified time of the file, in case of changes), a useful feature for a \fBmod_perl\fR environment in which a child process endures beyond the lifetime of a single request. Other aspects of the \fBmod_perl\fR environment cooperate nicely with this module, such as the ability to use a sub-request to fetch the full pathname for a file within the server space. This complements the \s-1HTML\s0 generation capabilities of the \fB\s-1CGI\s0\fR module, in which \f(CW\*(C`CGI::img\*(C'\fR wants a \s-1URL\s0 but \&\f(CW\*(C`attr_imgsize\*(C'\fR needs a file path: .PP .Vb 4 \& # Assume $Q is an object of class CGI, $r is an Apache request object. \& # $imgpath is a URL for something like "/img/redball.gif". \& $r->print($Q->img({ -src => $imgpath, \& attr_imgsize($r->lookup_uri($imgpath)->filename) })); .Ve .PP The advantage here, besides not having to hard-code the server document root, is that Apache passes the sub-request through the usual request lifecycle, including any stages that would re-write the \s-1URL\s0 or otherwise modify it. .SH "CAVEATS" .IX Header "CAVEATS" 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 \&\s-1MD5\s0 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. .PP As \fBImage::Magick\fR operates on file names, not handles, the use of it is restricted to cases where the input to \f(CW\*(C`imgsize\*(C'\fR is provided as file name. .SH "SEE ALSO" .IX Header "SEE ALSO" The \fBImage::Magick\fR and \fBImage::Info\fR Perl modules at \s-1CPAN\s0. .SH "AUTHORS" .IX Header "AUTHORS" Perl module interface by Randy J. Ray \fI(rjray@blackperl.com)\fR, original image-sizing code by Alex Knowles \fI(alex@ed.ac.uk)\fR and Andrew Tong \&\fI(werdna@ugcs.caltech.edu)\fR, used with their joint permission. .PP Some bug fixes submitted by Bernd Leibing \fI(bernd.leibing@rz.uni\-ulm.de)\fR. \&\s-1PPM/PGM/PBM\s0 sizing code contributed by Carsten Dominik \&\fI(dominik@strw.LeidenUniv.nl)\fR. Tom Metro \fI(tmetro@vl.com)\fR re-wrote the \s-1JPG\s0 and \s-1PNG\s0 code, and also provided a \s-1PNG\s0 image for the test suite. Dan Klein \&\fI(dvk@lonewolf.com)\fR contributed a re-write of the \s-1GIF\s0 code. Cloyce Spradling \&\fI(cloyce@headgear.org)\fR contributed \s-1TIFF\s0 sizing code and test images. Aldo Calpini \fI(a.calpini@romagiubileo.it)\fR suggested support of \s-1BMP\s0 images (which I \fIreally\fR should have already thought of :\-) and provided code to work with. A patch to allow html_imgsize to produce valid output for \s-1XHTML\s0, as well as some documentation fixes was provided by Charles Levert \&\fI(charles@comm.polymtl.ca)\fR. The ShockWave/Flash support was provided by Dmitry Dorofeev \fI(dima@yasp.com)\fR. Though I neglected to take note of who supplied the \s-1PSD\s0 (PhotoShop) code, a bug was identified by Alex Weslowski , who also provided a test image. \s-1PCD\s0 support was adapted from a script made available by Phil Greenspun, as guided to my attention by Matt Mueller \fImueller@wetafx.co.nz\fR. A thorough read of the documentation and source by Philip Newton \fIPhilip.Newton@datenrevision.de\fR found several typos and a small buglet. Ville Skyttä \fI(ville.skytta@iki.fi)\fR provided the \s-1MNG\s0 and the Image::Magick fallback code.