"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/Image/Size.pm" between
Image-Size-3.232.tar.gz and Image-Size-3.300.tar.gz

About: Image-Size determines the size of images in several common formats for e.g. it can add HEIGHT and WIDTH tags to HTML IMG directives (Perl module).

Size.pm  (Image-Size-3.232):Size.pm  (Image-Size-3.300)
############################################################################### ###############################################################################
# #
# This file copyright (c) 2012 by Randy J. Ray, all rights reserved # This file copyright (c) 2015 by Randy J. Ray, all rights reserved
# #
# Copying and distribution are permitted under the terms of the Artistic # Copying and distribution are permitted under the terms of the Artistic
# License 2.0 (http://www.opensource.org/licenses/artistic-license-2.0.php) or # License 2.0 (http://www.opensource.org/licenses/artistic-license-2.0.php) or
# the GNU LGPL (http://www.opensource.org/licenses/lgpl-2.1.php). # the GNU LGPL (http://www.opensource.org/licenses/lgpl-2.1.php).
# #
############################################################################### ###############################################################################
# #
# Once upon a time, this code was lifted almost verbatim from wwwis by Alex # Once upon a time, this code was lifted almost verbatim from wwwis by Alex
# Knowles, alex@ed.ac.uk. Since then, even I barely recognize it. It has # Knowles, alex@ed.ac.uk. Since then, even I barely recognize it. It has
# contributions, fixes, additions and enhancements from all over the world. # contributions, fixes, additions and enhancements from all over the world.
skipping to change at line 26 skipping to change at line 26
# #
############################################################################### ###############################################################################
package Image::Size; package Image::Size;
require 5.006001; require 5.006001;
# These are the Perl::Critic policies that are being turned off globally: # These are the Perl::Critic policies that are being turned off globally:
## no critic(RequireBriefOpen) ## no critic(RequireBriefOpen)
## no critic(ProhibitAutomaticExportation) ## no critic(ProhibitAutomaticExportation)
## no critic(ProhibitExplicitISA)
use strict; use strict;
use warnings; use warnings;
use bytes; use bytes;
use vars qw( use vars qw(
@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION $NO_CACHE %CACHE @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION $NO_CACHE %CACHE
$GIF_BEHAVIOR @TYPE_MAP %PCD_MAP $PCD_SCALE $READ_IN $LAST_POS $GIF_BEHAVIOR @TYPE_MAP %PCD_MAP $PCD_SCALE $READ_IN $LAST_POS
); );
use Exporter; use Exporter 'import';
BEGIN BEGIN
{ {
@ISA = qw(Exporter);
@EXPORT = qw(imgsize); @EXPORT = qw(imgsize);
@EXPORT_OK = qw(imgsize html_imgsize attr_imgsize @EXPORT_OK = qw(imgsize html_imgsize attr_imgsize
%CACHE $NO_CACHE $PCD_SCALE $GIF_BEHAVIOR); %CACHE $NO_CACHE $PCD_SCALE $GIF_BEHAVIOR);
%EXPORT_TAGS = ('all' => [ @EXPORT_OK ]); %EXPORT_TAGS = ('all' => [ @EXPORT_OK ]);
$VERSION = '3.232'; $VERSION = '3.300';
$VERSION = eval $VERSION; ## no critic(ProhibitStringyEval) $VERSION = eval $VERSION; ## no critic(ProhibitStringyEval)
# Default behavior for GIFs is to return the "screen" size # Default behavior for GIFs is to return the "screen" size
$GIF_BEHAVIOR = 0; $GIF_BEHAVIOR = 0;
} }
# This allows people to specifically request that the cache not be used # This allows people to specifically request that the cache not be used
$NO_CACHE = 0; $NO_CACHE = 0;
# Package lexicals - invisible to outside world, used only in imgsize # Package lexicals - invisible to outside world, used only in imgsize
skipping to change at line 75 skipping to change at line 73
qr{/[*] XPM [*]/} => \&xpmsize, qr{/[*] XPM [*]/} => \&xpmsize,
qr{^MM\x00\x2a} => \&tiffsize, qr{^MM\x00\x2a} => \&tiffsize,
qr{^II\x2a\x00} => \&tiffsize, qr{^II\x2a\x00} => \&tiffsize,
qr{^BM} => \&bmpsize, qr{^BM} => \&bmpsize,
qr{^8BPS} => \&psdsize, qr{^8BPS} => \&psdsize,
qr{^PCD_OPA} => \&pcdsize, qr{^PCD_OPA} => \&pcdsize,
qr{^FWS} => \&swfsize, qr{^FWS} => \&swfsize,
qr{^CWS} => \&swfmxsize, qr{^CWS} => \&swfmxsize,
qr{^\x8aMNG\x0d\x0a\x1a\x0a} => \&mngsize, qr{^\x8aMNG\x0d\x0a\x1a\x0a} => \&mngsize,
qr{^\x01\x00\x00\x00} => \&emfsize, qr{^\x01\x00\x00\x00} => \&emfsize,
qr{^RIFF(?s:....)WEBP} => \&webpsize,
qr{^\x00\x00\x01\x00} => \&icosize,
qr{^\x00\x00\x02\x00} => \&cursize,
); );
# Kodak photo-CDs are weird. Don't ask me why, you really don't want details. # Kodak photo-CDs are weird. Don't ask me why, you really don't want details.
%PCD_MAP = ( 'base/16' => [ 192, 128 ], %PCD_MAP = ( 'base/16' => [ 192, 128 ],
'base/4' => [ 384, 256 ], 'base/4' => [ 384, 256 ],
'base' => [ 768, 512 ], 'base' => [ 768, 512 ],
'base4' => [ 1536, 1024 ], 'base4' => [ 1536, 1024 ],
'base16' => [ 3072, 2048 ], 'base16' => [ 3072, 2048 ],
'base64' => [ 6144, 4096 ], ); 'base64' => [ 6144, 4096 ], );
# Default scale for PCD images # Default scale for PCD images
$PCD_SCALE = 'base'; $PCD_SCALE = 'base';
skipping to change at line 134 skipping to change at line 135
return $content; return $content;
}; };
sub imgsize ## no critic(ProhibitExcessComplexity) sub imgsize ## no critic(ProhibitExcessComplexity)
{ {
my $stream = shift; my $stream = shift;
my ($handle, $header); my ($handle, $header);
my ($x, $y, $id, $mtime, @list); my ($x, $y, $id, $mtime, @list);
# These only used if $stream is an existant open FH # These only used if $stream is an existing open FH
my ($save_pos, $need_restore) = (0, 0); my ($save_pos, $need_restore) = (0, 0);
# This is for when $stream is a locally-opened file # This is for when $stream is a locally-opened file
my $need_close = 0; my $need_close = 0;
# This will contain the file name, if we got one # This will contain the file name, if we got one
my $file_name = undef; my $file_name = undef;
$header = q{}; $header = q{};
if (ref($stream) eq 'SCALAR') if (ref($stream) eq 'SCALAR')
{ {
skipping to change at line 159 skipping to change at line 160
elsif (ref $stream) elsif (ref $stream)
{ {
# I no longer require $stream to be in the IO::* space. So I'm assuming # I no longer require $stream to be in the IO::* space. So I'm assuming
# you don't hose yourself by passing a ref that can't do fileops. If # you don't hose yourself by passing a ref that can't do fileops. If
# you do, you fix it. # you do, you fix it.
$handle = $stream; $handle = $stream;
$READ_IN = $read_io; $READ_IN = $read_io;
$save_pos = tell $handle; $save_pos = tell $handle;
$need_restore = 1; $need_restore = 1;
# First alteration (didn't wait long, did I?) to the existant handle: # First alteration (didn't wait long, did I?) to the existing handle:
# #
# assist dain-bramaged operating systems -- SWD # assist dain-bramaged operating systems -- SWD
# SWD: I'm a bit uncomfortable with changing the mode on a file # SWD: I'm a bit uncomfortable with changing the mode on a file
# that something else "owns" ... the change is global, and there # that something else "owns" ... the change is global, and there
# is no way to reverse it. # is no way to reverse it.
# But image files ought to be handled as binary anyway. # But image files ought to be handled as binary anyway.
binmode $handle; binmode $handle;
seek $handle, 0, 0; seek $handle, 0, 0;
read $handle, $header, 256; read $handle, $header, 256;
seek $handle, 0, 0; seek $handle, 0, 0;
skipping to change at line 237 skipping to change at line 238
$tm_idx += 2; $tm_idx += 2;
} }
# Added as an afterthought: I'm probably not the only one who uses the # Added as an afterthought: I'm probably not the only one who uses the
# same shaded-sphere image for several items on a bulleted list: # same shaded-sphere image for several items on a bulleted list:
if (! ($NO_CACHE or (ref $stream) or (! defined $x))) if (! ($NO_CACHE or (ref $stream) or (! defined $x)))
{ {
$CACHE{$stream} = join q{,}, $mtime, $x, $y, $id; $CACHE{$stream} = join q{,}, $mtime, $x, $y, $id;
} }
# If we were passed an existant file handle, we need to restore the # If we were passed an existing file handle, we need to restore the
# old filepos: # old filepos:
if ($need_restore) if ($need_restore)
{ {
seek $handle, $save_pos, 0; seek $handle, $save_pos, 0;
} }
# ...and if we opened the file ourselves, we need to close it # ...and if we opened the file ourselves, we need to close it
if ($need_close) if ($need_close)
{ {
close $handle; ## no critic(RequireCheckedClose) close $handle; ## no critic(RequireCheckedClose)
} }
skipping to change at line 327 skipping to change at line 328
return $retval ? 1 : 0; return $retval ? 1 : 0;
} }
sub html_imgsize sub html_imgsize
{ {
my @args = @_; my @args = @_;
@args = imgsize(@args); @args = imgsize(@args);
# Use lowercase and quotes so that it works with xhtml. # Use lowercase and quotes so that it works with xhtml.
return ((defined $args[0]) ? return ((defined $args[0]) ?
sprintf('width="%d" height="%d"', @args) : sprintf('width="%d" height="%d"', @args[0,1]) :
undef); undef);
} }
sub attr_imgsize sub attr_imgsize
{ {
my @args = @_; my @args = @_;
@args = imgsize(@args); @args = imgsize(@args);
return ((defined $args[0]) ? return ((defined $args[0]) ?
(('-width', '-height', @args)[0, 2, 1, 3]) : (('-width', '-height', @args)[0, 2, 1, 3]) :
skipping to change at line 367 skipping to change at line 368
my $val = shift; my $val = shift;
# "no critic" because I want it clear which args are being used by # "no critic" because I want it clear which args are being used by
# substr() versus unpack(). # substr() versus unpack().
## no critic (ProhibitParensWithBuiltins) ## no critic (ProhibitParensWithBuiltins)
return unpack 'N', pack 'B32', substr(('0' x 32) . $val, -32); return unpack 'N', pack 'B32', substr(('0' x 32) . $val, -32);
} }
########################################################################### ###########################################################################
# Subroutine gets the size of the specified GIF # Subroutine gets the size of the specified GIF
########################################################################### ###########################################################################
sub gifsize sub gifsize ## no critic(ProhibitExcessComplexity)
{ {
my $stream = shift; my $stream = shift;
# We use bitwise-and here:
## no critic(ProhibitBitwiseOperators)
my ($cmapsize, $buf, $sh, $sw, $x, $y, $type); my ($cmapsize, $buf, $sh, $sw, $x, $y, $type);
my $gif_blockskip = sub { my $gif_blockskip = sub {
my ($skip, $blocktype) = @_; my ($skip, $blocktype) = @_;
my ($lbuf); my ($lbuf);
$READ_IN->($stream, $skip); # Skip header (if any) $READ_IN->($stream, $skip); # Skip header (if any)
while (1) while (1)
{ {
if (img_eof($stream)) if (img_eof($stream))
skipping to change at line 643 skipping to change at line 641
# Verify that it's a valid segment. # Verify that it's a valid segment.
if ($marker ne $MARKER) if ($marker ne $MARKER)
{ {
# Was it there? # Was it there?
$id = 'JPEG marker not found'; $id = 'JPEG marker not found';
last; last;
} }
elsif ((ord($code) >= $SIZE_FIRST) && (ord($code) <= $SIZE_LAST)) elsif ((ord($code) >= $SIZE_FIRST) && (ord($code) <= $SIZE_LAST))
{ {
# Segments that contain size info # Segments that contain size info
($y, $x) = unpack 'xnn', $READ_IN->($stream, 5); $length = 5;
my $buf = $READ_IN->($stream, $length);
# unpack dies on truncated data
last if (length($buf) < $length);
($y, $x) = unpack 'xnn', $buf;
$id = 'JPG'; $id = 'JPG';
last; last;
} }
else else
{ {
# Dummy read to skip over data # Dummy read to skip over data
$READ_IN->($stream, ($length - 2)); $READ_IN->($stream, ($length - 2));
} }
} }
skipping to change at line 794 skipping to change at line 796
# #
# Adapted from code contributed by Aldo Calpini <a.calpini@romagiubileo.it> # Adapted from code contributed by Aldo Calpini <a.calpini@romagiubileo.it>
sub bmpsize sub bmpsize
{ {
my $stream = shift; my $stream = shift;
my ($x, $y, $id) = (undef, undef, 'Unable to determine size of BMP data'); my ($x, $y, $id) = (undef, undef, 'Unable to determine size of BMP data');
my $buffer; my $buffer;
$buffer = $READ_IN->($stream, 26); $buffer = $READ_IN->($stream, 26);
($x, $y) = unpack 'x18VV', $buffer; my $header_size = unpack 'x14V', $buffer;
if ($header_size == 12)
{
($x, $y) = unpack 'x18vv', $buffer; # old OS/2 header
}
else
{
($x, $y) = unpack 'x18VV', $buffer; # modern Windows header
}
if (defined $x and defined $y) if (defined $x and defined $y)
{ {
$id = 'BMP'; $id = 'BMP';
} }
return ($x, $y, $id); return ($x, $y, $id);
} }
# psdsize: determine the size of a PhotoShop save-file (*.PSD) # psdsize: determine the size of a PhotoShop save-file (*.PSD)
sub psdsize sub psdsize
skipping to change at line 844 skipping to change at line 854
return ($x, $y, 'SWF'); return ($x, $y, 'SWF');
} }
# Suggested by Matt Mueller <mueller@wetafx.co.nz>, and based on a piece of # Suggested by Matt Mueller <mueller@wetafx.co.nz>, and based on a piece of
# sample Perl code by a currently-unknown author. Credit will be placed here # sample Perl code by a currently-unknown author. Credit will be placed here
# once the name is determined. # once the name is determined.
sub pcdsize sub pcdsize
{ {
my $stream = shift; my $stream = shift;
# We use bitwise-and here:
## no critic(ProhibitBitwiseOperators)
my ($x, $y, $id) = (undef, undef, 'Unable to determine size of PCD data'); my ($x, $y, $id) = (undef, undef, 'Unable to determine size of PCD data');
my $buffer = $READ_IN->($stream, 0xf00); my $buffer = $READ_IN->($stream, 0xf00);
# Second-tier sanity check # Second-tier sanity check
if (substr($buffer, 0x800, 3) ne 'PCD') if (substr($buffer, 0x800, 3) ne 'PCD')
{ {
return ($x, $y, $id); return ($x, $y, $id);
} }
my $orient = ord(substr $buffer, 0x0e02, 1) & 1; # Clear down to one bit my $orient = ord(substr $buffer, 0x0e02, 1) & 1; # Clear down to one bit
skipping to change at line 913 skipping to change at line 920
unpack 'x8V4', $buffer; unpack 'x8V4', $buffer;
# The four values describe a box *around* the image, not *of* the image. # The four values describe a box *around* the image, not *of* the image.
# In other words, the dimensions are not inclusive. # In other words, the dimensions are not inclusive.
$x = $bottomright_x - $topleft_x - 1; $x = $bottomright_x - $topleft_x - 1;
$y = $bottomright_y - $topleft_y - 1; $y = $bottomright_y - $topleft_y - 1;
return ($x, $y, 'EMF'); return ($x, $y, 'EMF');
} }
# WEBP files, see https://developers.google.com/speed/webp/docs/riff_container
# Added by Baldur Kristinsson, github.com/bk
sub webpsize {
my $img = shift;
# There are 26 bytes of lead-in, before the width and height info:
# 1. WEBP container
# - 'RIFF', 4 bytes
# - filesize, 4 bytes
# - 'WEBP', 4 bytes
# 2. VP8 frame
# - 'VP8', 3 bytes
# - frame meta, 8 bytes
# - marker, 3 bytes
my $buf = $READ_IN->($img, 4, 26);
my ($raw_w, $raw_h) = unpack 'SS', $buf;
my $b14 = 2**14 - 1;
# The width and height values contain a 2-bit scaling factor,
# which is left-shifted by 14 bits. We ignore this, since it seems
# not to be relevant for our purposes. WEBP images in actual use
# all seem to have a scaling factor of 0, anyway. (The meaning
# of the scaling factor is as follows: 0=no upscale, 1=upscale by 5/4,
# 2=upscale by 5/3, 3=upscale by 2).
#
# my $wscale = $raw_w >> 14;
# my $hscale = $raw_h >> 14;
my $x = $raw_w & $b14;
my $y = $raw_h & $b14;
return ($x, $y, 'WEBP');
}
# ICO files, originally contributed by Thomas Walloschke <thw@cpan.org>,
# see https://rt.cpan.org/Public/Bug/Display.html?id=46279
# (revised by Baldur Kristinsson, github.com/bk)
sub icosize {
my $img = shift;
my ($x, $y) = unpack 'CC', $READ_IN->($img, 2, 6);
if ($x == 0) { $x = 256; }
if ($y == 0) { $y = 256; }
return ($x, $y, 'ICO');
}
# CUR files, originally contributed by Thomas Walloschke <thw@cpan.org>,
# see https://rt.cpan.org/Public/Bug/Display.html?id=46279
# (revised by Baldur Kristinsson, github.com/bk)
sub cursize {
my ($x, $y, $ico) = icosize(shift);
return ($x, $y, 'CUR');
}
1; 1;
__END__ __END__
=encoding utf8
=head1 NAME =head1 NAME
Image::Size - read the dimensions of an image in several popular formats Image::Size - read the dimensions of an image in several popular formats
=head1 SYNOPSIS =head1 SYNOPSIS
use Image::Size; use Image::Size;
# Get the size of globe.gif # Get the size of globe.gif
($globe_x, $globe_y) = imgsize("globe.gif"); ($globe_x, $globe_y) = imgsize("globe.gif");
# Assume X=60 and Y=40 for remaining examples # Assume X=60 and Y=40 for remaining examples
skipping to change at line 1059 skipping to change at line 1120
=item PSD (Adobe PhotoShop) =item PSD (Adobe PhotoShop)
=item SWF (ShockWave/Flash) =item SWF (ShockWave/Flash)
=item CWS (FlashMX, compressed SWF, Flash 6) =item CWS (FlashMX, compressed SWF, Flash 6)
=item PCD (Kodak PhotoCD, see notes below) =item PCD (Kodak PhotoCD, see notes below)
=item EMF (Windows Enhanced Metafile Format) =item EMF (Windows Enhanced Metafile Format)
=item WEBP
=item ICO (Microsoft icon format)
=item CUR (Microsoft mouse cursor format)
=back =back
Additionally, if the B<Image::Magick> module is present, the file types Additionally, if the B<Image::Magick> module is present, the file types
supported by it are also supported by Image::Size. See also L<"CAVEATS">. supported by it are also supported by Image::Size. See also L<"CAVEATS">.
When using the C<imgsize> interface, there is a third, unused value returned When using the C<imgsize> interface, there is a third, unused value returned
if the programmer wishes to save and examine it. This value is the identity of 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 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 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 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 C<imgsize> routine. value, so those wishing to use it must use the base C<imgsize> routine.
Note that when the B<Image::Magick> fallback is used (for all non-natively Note that when the B<Image::Magick> fallback is used (for all non-natively
supported files), the data type identity comes directly from the 'format' supported files), the data type identity comes directly from the 'format'
parameter reported by B<Image::Magick>, so it may not meet the 2-3 letter parameter reported by B<Image::Magick>, so it may not meet the 2-3 letter
abbreviation format. For example, a WBMP file might be reported as abbreviation format. For example, a WBMP file might be reported as
'Wireless Bitmap (level 0) image' in this case. 'Wireless Bitmap (level 0) image' in this case.
=head2 Information Cacheing and C<$NO_CACHE> =head2 Information Caching and C<$NO_CACHE>
When a filename is passed to any of the sizing routines, the default behavior 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 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 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 CGI updated. This was originally added due to the fact that a number of CGI
applications were using this library to generate attributes for pages that applications were using this library to generate attributes for pages that
often used the same graphical element many times over. often used the same graphical element many times over.
However, the cacheing can lead to problems when the files are generated However, the caching can lead to problems when the files are generated
dynamically, at a rate that exceeds the resolution of the modification-time dynamically, at a rate that exceeds the resolution of the modification-time
value on the filesystem. Thus, the optionally-importable control variable value on the filesystem. Thus, the optionally-importable control variable
C<$NO_CACHE> has been introduced. If this value is anything that evaluates to a C<$NO_CACHE> 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 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 cacheing is disabled until such time as the program re-enables it by setting
the value to false. the value to false.
The parameter C<$NO_CACHE> may be imported as with the B<imgsize> routine, and The parameter C<$NO_CACHE> may be imported as with the B<imgsize> routine, and
is also imported when using the import tag B<C<:all>>. If the programmer is also imported when using the import tag B<C<:all>>. If the programmer
chooses not to import it, it is still accessible by the fully-qualified package chooses not to import it, it is still accessible by the fully-qualified package
skipping to change at line 1160 skipping to change at line 1227
Also note that the library makes no effort to read enough of the PCD file to Also note that the library makes no effort to read enough of the PCD file to
verify that the requested resolution is available. The point of this library 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 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 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 portrait or landscape. That is in fact all that the library extracts from the
image file. image file.
=head2 Controlling Behavior with GIF Images =head2 Controlling Behavior with GIF Images
GIF images present a sort of unusual situation when it comes to reading size. GIF 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 Because GIFs can be a series of sub-images to be played as an animated
sequence, what part does the user want to get the size for? sequence, what part does the user want to get the size for?
When dealing with GIF files, the user may control the behavior by setting the When dealing with GIF files, the user may control the behavior by setting the
global value B<$Image::Size::GIF_BEHAVIOR>. Like the PCD setting, this may global value B<$Image::Size::GIF_BEHAVIOR>. Like the PCD setting, this may
be imported when loading the library. Three values are recognized by the be imported when loading the library. Three values are recognized by the
GIF-handling code: GIF-handling code:
=over 4 =over 4
=item 0 =item Z<>0
This is the default value. When this value is chosen, the returned dimensions This is the default value. When this value is chosen, the returned dimensions
are those of the "screen". The "screen" is the display area that the GIF are those of the "screen". The "screen" is the display area that the GIF
declares in the first data block of the file. No sub-images will be greater 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 than this in size; if they are, the specification dictates that they be
cropped to fit within the box. cropped to fit within the box.
This is also the fastest method for sizing the GIF, as it reads the least This is also the fastest method for sizing the GIF, as it reads the least
amount of data from the image stream. amount of data from the image stream.
=item 1 =item Z<>1
If this value is set, then the size of the first sub-image within the GIF is If this value is set, then the size of the first sub-image within the GIF is
returned. For plain (non-animated) GIF files, this would be the same as the returned. For plain (non-animated) GIF files, this would be the same as the
screen (though it doesn't have to be, strictly-speaking). screen (though it doesn't have to be, strictly-speaking).
When the first image descriptor block is read, the code immediately returns, When the first image descriptor block is read, the code immediately returns,
making this only slightly-less efficient than the previous setting. making this only slightly-less efficient than the previous setting.
=item 2 =item Z<>2
If this value is chosen, then the code loops through all the sub-images of the If this value is chosen, then the code loops through all the sub-images of the
animated GIF, and returns the dimensions of the largest of them. animated GIF, and returns the dimensions of the largest of them.
This option requires that the full GIF image be read, in order to ensure that This option requires that the full GIF image be read, in order to ensure that
the largest is found. the largest is found.
=back =back
Any value outside this range will produce an error in the GIF code before any Any value outside this range will produce an error in the GIF code before any
skipping to change at line 1299 skipping to change at line 1366
$r->print($Q->img({ -src => $imgpath, $r->print($Q->img({ -src => $imgpath,
attr_imgsize($r->lookup_uri($imgpath)->filename) })); attr_imgsize($r->lookup_uri($imgpath)->filename) }));
The advantage here, besides not having to hard-code the server document root, 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, is that Apache passes the sub-request through the usual request lifecycle,
including any stages that would re-write the URL or otherwise modify it. including any stages that would re-write the URL or otherwise modify it.
=head1 DIAGNOSTICS =head1 DIAGNOSTICS
The base routine, C<imgsize>, returns B<undef> as the first value in its list The base routine, C<imgsize>, returns B<undef> as the first value in its list
when an error has occured. The third element contains a descriptive when an error has occurred. The third element contains a descriptive
error message. error message.
The other two routines simply return B<undef> in the case of error. The other two routines simply return B<undef> in the case of error.
=head1 CAVEATS =head1 CAVEATS
Caching of size data can only be done on inputs that are file names. Open 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 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 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, 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. however, wish to lengthen the dependency list by another item at this time.
As B<Image::Magick> operates on file names, not handles, the use of it is As B<Image::Magick> operates on file names, not handles, the use of it is
restricted to cases where the input to C<imgsize> is provided as file name. restricted to cases where the input to C<imgsize> is provided as file name.
=head1 SEE ALSO =head1 SEE ALSO
L<Image::Magick|Image::Magick> and L<Image::Info|Image::Info> Perl modules at L<Image::Magick|Image::Magick> and L<Image::Info|Image::Info> Perl modules at
CPAN. The B<Graphics::Magick> Perl API at CPAN. The B<Graphics::Magick> Perl API at
L<http://www.graphicsmagick.org/perl.html>. L<http://www.graphicsmagick.org/perl.html>.
skipping to change at line 1344 skipping to change at line 1411
I I<really> should have already thought of :-) and provided code to work I I<really> should have already thought of :-) and provided code to work
with. A patch to allow html_imgsize to produce valid output for XHTML, as with. A patch to allow html_imgsize to produce valid output for XHTML, as
well as some documentation fixes was provided by Charles Levert well as some documentation fixes was provided by Charles Levert
I<(charles@comm.polymtl.ca)>. The ShockWave/Flash support was provided by I<(charles@comm.polymtl.ca)>. The ShockWave/Flash support was provided by
Dmitry Dorofeev I<(dima@yasp.com)>. Though I neglected to take note of who Dmitry Dorofeev I<(dima@yasp.com)>. Though I neglected to take note of who
supplied the PSD (PhotoShop) code, a bug was identified by Alex Weslowski supplied the PSD (PhotoShop) code, a bug was identified by Alex Weslowski
<aweslowski@rpinteractive.com>, who also provided a test image. PCD support <aweslowski@rpinteractive.com>, who also provided a test image. PCD support
was adapted from a script made available by Phil Greenspun, as guided to my was adapted from a script made available by Phil Greenspun, as guided to my
attention by Matt Mueller I<mueller@wetafx.co.nz>. A thorough read of the attention by Matt Mueller I<mueller@wetafx.co.nz>. A thorough read of the
documentation and source by Philip Newton I<Philip.Newton@datenrevision.de> documentation and source by Philip Newton I<Philip.Newton@datenrevision.de>
found several typos and a small buglet. Ville Skytt I<(ville.skytta@iki.fi)> found several typos and a small buglet. Ville Skytt I<(ville.skytta@iki.fi)>
provided the MNG and the Image::Magick fallback code. Craig MacKenna provided the MNG and the Image::Magick fallback code. Craig MacKenna
I<(mackenna@animalhead.com)> suggested making the cache available so that it I<(mackenna@animalhead.com)> suggested making the cache available so that it
could be used with shared memory, and helped test my change before release. could be used with shared memory, and helped test my change before release.
=head1 BUGS =head1 BUGS
Please report any bugs or feature requests to Please report any bugs or feature requests to
C<bug-image-size at rt.cpan.org>, or through the web interface at C<bug-image-size at rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Image-Size>. I will be L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Image-Size>. I will be
notified, and then you'll automatically be notified of progress on notified, and then you'll automatically be notified of progress on
skipping to change at line 1383 skipping to change at line 1450
=item * Search CPAN =item * Search CPAN
L<http://search.cpan.org/dist/Image-Size> L<http://search.cpan.org/dist/Image-Size>
=item * Project page on GitHub =item * Project page on GitHub
L<http://github.com/rjray/image-size> L<http://github.com/rjray/image-size>
=back =back
=head1 REPOSITORY
L<https://github.com/rjray/image-size>
=head1 LICENSE AND COPYRIGHT =head1 LICENSE AND COPYRIGHT
This file and the code within are copyright (c) 1996-2009 by Randy J. Ray. This file and the code within are copyright (c) 1996-2009 by Randy J. Ray.
Copying and distribution are permitted under the terms of the Artistic Copying and distribution are permitted under the terms of the Artistic
License 2.0 (L<http://www.opensource.org/licenses/artistic-license-2.0.php>) or License 2.0 (L<http://www.opensource.org/licenses/artistic-license-2.0.php>) or
the GNU LGPL 2.1 (L<http://www.opensource.org/licenses/lgpl-2.1.php>). the GNU LGPL 2.1 (L<http://www.opensource.org/licenses/lgpl-2.1.php>).
=head1 AUTHOR =head1 AUTHOR
 End of changes. 29 change blocks. 
28 lines changed or deleted 99 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS