Image-Size
view release on metacpan or search on metacpan
* t/all.t
Applied a patch from mrj@mrj.spb.ru to fix usage of the
Compress::Zlib module in the handling of compressed flash
files. Added a new SWF file to test this, and added reference
to the file in MANIFEST and t/all.t.
* MANIFEST
* Makefile.PL
* Size.pm
* t/magick.t (added)
Delay Image::Magick loading until it is needed. (Mark
Stosberg). Add support for Graphics::Magick as an alternative
to Image::Magick. If either Graphics::Magick or Image::Magick
is loaded into memory that module will be used. Otherwise, they
are both tried to be loaded, with Graphics::Magick being tried
first. (Mark Stosberg). This patch also adds a new test suite,
t/magick.t, to the distribution and modifies both MANIFEST and
Makefile.PL (to add a build-dependancy on Test::More).
* t/all.t
With Test::More now required for building, converted t/all.t to
use it.
* Size.pm, revision 109
Small change in the block that sets up read from a scalar ref,
to avoid warnings about undef values (in case $stream is a
reference to an undef value).
2.99 Saturday May 4, 2002, 08:23:42 AM UTC
* Size.pm, revision 106
Applied two patches from Ville Skyttä <ville.skytta@iki.fi>,
providing MNG and Image::Magick support.
2.98 Saturday March 2, 2002, 08:36:07 PM UTC
* Size.pm, revision 104
Bumped the version number. Wouldn't have to keep remembering
this if I'd move it to the Makefile.PL.
* Size.pm, revision 103
Fixed some documentation issues and a small buglet in an error
message.
ChangeLog.xml view on Meta::CPAN
</description>
</change>
<change>
<fileset>
<file path="Size.pm" />
<file path="MANIFEST" />
<file path="Makefile.PL" />
<file action="ADD" path="t/magick.t" />
</fileset>
<description>
Delay Image::Magick loading until it is needed. (Mark Stosberg). Add
support for Graphics::Magick as an alternative to Image::Magick. If
either Graphics::Magick or Image::Magick is loaded into memory that
module will be used. Otherwise, they are both tried to be loaded, with
Graphics::Magick being tried first. (Mark Stosberg). This patch also
adds a new test suite, t/magick.t, to the distribution and modifies
both MANIFEST and Makefile.PL (to add a build-dependancy on
Test::More).
</description>
</change>
<change>
<file path="t/all.t" />
<description>
ChangeLog.xml view on Meta::CPAN
avoid warnings about undef values (in case $stream is a reference to
an undef value).
</description>
</change>
</release>
<release version="2.99" sc:tag="v2_99" date="2002-05-04T08:23:42.000000Z">
<change date="2002-05-04T08:23:29.000000Z" author="rjray">
<file path="Size.pm" revision="106"/>
<description>
Applied two patches from Ville Skyttä <ville.skytta@iki.fi>,
providing MNG and Image::Magick support.
</description>
</change>
</release>
<release version="2.98" sc:tag="v2_98" date="2002-03-02T20:36:07.000000Z">
<change date="2002-03-02T07:47:11.000000Z" author="rjray">
<file path="Size.pm" revision="104"/>
<description>
Bumped the version number. Wouldn't have to keep remembering this if
I'd move it to the Makefile.PL.
</description>
WHAT IS IT
----------
Image::Size is a library based on the image-sizing code in the wwwimagesize
script, a tool that analyzes HTML files and adds HEIGHT and WIDTH tags to IMG
directives. Image::Size has generalized that code to return a raw (X, Y) pair,
and included wrappers to pre-format that output into either HTML or a set of
attribute pairs suitable for the CGI.pm library by Lincoln Stein. Currently,
Image::Size can size images in XPM, XBM, GIF, JPEG, PNG, MNG, TIFF, the PPM
family of formats (PPM/PGM/PBM) and if Image::Magick is installed, the formats
supported by it.
I did this because my old WWW server generated a lot of documents on demand
rather than keeping them in static files. These documents not only used
directional icons and buttons, but other graphics to annotate and highlight
sections of the text. Without size attributes, browsers cannot render the text
of a page until the image data is loaded and the size known for layout. This
library enables scripts to size their images at run-time and include that as
part of the generated HTML. Or for any other utility that uses and manipulates
graphics. The idea of the basic interface + wrappers is to not limit the
README.textile view on Meta::CPAN
h1. Image::Size - Determine the size of images in several common formats
Version: 3.300 (See CHANGES below)
h2. WHAT IS IT
Image::Size is a library based on the image-sizing code in the wwwimagesize script, a tool that analyzes HTML files and adds HEIGHT and WIDTH tags to IMG directives. Image::Size has generalized that code to return a raw (X, Y) pair, and included wrap...
I did this because my old WWW server generated a lot of documents on demand rather than keeping them in static files. These documents not only used directional icons and buttons, but other graphics to annotate and highlight sections of the text. With...
h2. USING Image::Size IN YOUR SCRIPTS
Image::Size has pod documentation that gives a more complete overview, but in a nutshell:
<pre>
<code>
lib/Image/Size.pm view on Meta::CPAN
binmode $handle;
read $handle, $header, 256;
seek $handle, 0, 0;
$READ_IN = $read_io;
$file_name = $stream;
}
$LAST_POS = 0;
# Right now, $x, $y and $id are undef. If the while-loop below doesn't
# match the header to a file-type and call a subroutine, then the later
# block that tried Image::Magick will default to setting the id/error to
# "unknown file type".
my $tm_idx = 0;
while ($tm_idx < @TYPE_MAP)
{
if ($header =~ $TYPE_MAP[$tm_idx])
{
($x, $y, $id) = $TYPE_MAP[$tm_idx + 1]->($handle);
last;
}
$tm_idx += 2;
lib/Image/Size.pm view on Meta::CPAN
# ...and if we opened the file ourselves, we need to close it
if ($need_close)
{
close $handle; ## no critic(RequireCheckedClose)
}
if (! defined $id)
{
if ($file_name)
{
# Image::Magick operates on file names.
($x, $y, $id) = imagemagick_size($file_name);
}
else
{
$id = 'Data stream is not a known image file format';
}
}
# results:
return (wantarray) ? ($x, $y, $id) : ();
}
sub imagemagick_size
{
my $file_name = shift;
my $module_name;
# First see if we have already loaded Graphics::Magick or Image::Magick
# If so, just use whichever one is already loaded.
if (exists $INC{'Graphics/Magick.pm'})
{
$module_name = 'Graphics::Magick';
}
elsif (exists $INC{'Image/Magick.pm'})
{
$module_name = 'Image::Magick';
}
# If neither are already loaded, try loading either one.
elsif (_load_magick_module('Graphics::Magick'))
{
$module_name = 'Graphics::Magick';
}
elsif (_load_magick_module('Image::Magick'))
{
$module_name = 'Image::Magick';
}
if ($module_name)
{
my $img = $module_name->new();
my $x = $img->Read($file_name);
# Image::Magick error handling is a bit weird, see
# <http://www.simplesystems.org/ImageMagick/www/perl.html#erro>
if("$x") {
return (undef, undef, "$x");
} else {
return ($img->Get('width', 'height', 'format'));
}
}
else {
return (undef, undef, 'Data stream is not a known image file format');
}
}
# load Graphics::Magick or Image::Magick if one is not already loaded.
sub _load_magick_module {
my $module_name = shift;
my $retval = eval {
local $SIG{__DIE__} = q{};
require $module_name;
1;
};
return $retval ? 1 : 0;
}
lib/Image/Size.pm view on Meta::CPAN
=item EMF (Windows Enhanced Metafile Format)
=item WEBP
=item ICO (Microsoft icon format)
=item CUR (Microsoft mouse cursor format)
=back
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">.
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
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 C<imgsize> routine.
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'
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
'Wireless Bitmap (level 0) image' in this case.
=head2 Information Caching and C<$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 CGI
applications were using this library to generate attributes for pages that
lib/Image/Size.pm view on Meta::CPAN
The other two routines simply return B<undef> in the case of error.
=head1 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
MD5 module, and perhaps in the future I will make that an option. I do not,
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
restricted to cases where the input to C<imgsize> is provided as file name.
=head1 SEE ALSO
L<Image::Magick|Image::Magick> and L<Image::Info|Image::Info> Perl modules at
CPAN. The B<Graphics::Magick> Perl API at
L<http://www.graphicsmagick.org/perl.html>.
=head1 CONTRIBUTORS
Perl module interface by Randy J. Ray I<(rjray@blackperl.com)>, original
image-sizing code by Alex Knowles I<(alex@ed.ac.uk)> and Andrew Tong
I<(werdna@ugcs.caltech.edu)>, used with their joint permission.
Some bug fixes submitted by Bernd Leibing I<(bernd.leibing@rz.uni-ulm.de)>.
lib/Image/Size.pm view on Meta::CPAN
with. A patch to allow html_imgsize to produce valid output for XHTML, as
well as some documentation fixes was provided by Charles Levert
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
supplied the PSD (PhotoShop) code, a bug was identified by Alex Weslowski
<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
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>
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
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.
=head1 BUGS
Please report any bugs or feature requests to
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
notified, and then you'll automatically be notified of progress on
your bug as I make changes.
#!/usr/bin/perl -w
# Tests related to Image::Magick and Graphics::Magick
use Test::More;
use Image::Size;
plan tests => 1;
# This test should work whether or not Image::Magick is installed.
ok(!(exists $INC{'Image/Magick.pm'}),
'Image::Magick should not be loaded until it is needed if it available')
|| diag "Image::Magick loaded at: $INC{'Image/Magick.pm'}";
( run in 0.696 second using v1.01-cache-2.11-cpan-beeb90c9504 )