Mon Feb 7 22:30:18 EST 2005 Mark Stosberg <mark@summersault.com>
* delay Image::Magick module loading, and add Graphics::Magick support
diff -rN -u Image-Size-2.992-old/ChangeLog Image-Size-2.992-new/ChangeLog
--- Image-Size-2.992-old/ChangeLog 2005-02-07 22:32:14.000000000 -0500
+++ Image-Size-2.992-new/ChangeLog 2005-02-07 22:30:14.000000000 -0500
@@ -1,5 +1,11 @@
CHANGE HISTORY
+* 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).
+
Changes in 2.992:
* Added support for FlashMX (Shockwave Flash ver. 6), as contributed by
diff -rN -u Image-Size-2.992-old/MANIFEST Image-Size-2.992-new/MANIFEST
--- Image-Size-2.992-old/MANIFEST 2005-02-07 22:32:14.000000000 -0500
+++ Image-Size-2.992-new/MANIFEST 2005-02-07 21:54:00.000000000 -0500
@@ -18,3 +18,4 @@
t/bexjdic.tif
t/yasp.swf
t/468x60.psd
+t/magick.t
diff -rN -u Image-Size-2.992-old/Makefile.PL Image-Size-2.992-new/Makefile.PL
--- Image-Size-2.992-old/Makefile.PL 2005-02-07 22:32:14.000000000 -0500
+++ Image-Size-2.992-new/Makefile.PL 2005-02-07 21:53:40.000000000 -0500
@@ -8,7 +8,7 @@
(ABSTRACT => 'A library to extract height/width from images',
AUTHOR => 'Randy J. Ray (rjray@blackperl.com)') : ()),
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz' },
- PREREQ_PM => { File::Spec => 0 },
+ PREREQ_PM => { File::Spec => 0, Test::More => 0, },
EXE_FILES => ['imgsize'],
clean => { FILES =>
'Image-Size-* *.spec *.rpm rpmrc rpmmacro' },
diff -rN -u Image-Size-2.992-old/Size.pm Image-Size-2.992-new/Size.pm
--- Image-Size-2.992-old/Size.pm 2005-02-07 22:32:14.000000000 -0500
+++ Image-Size-2.992-new/Size.pm 2005-02-07 22:19:46.000000000 -0500
@@ -26,7 +26,7 @@
use AutoLoader 'AUTOLOAD';
require Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $revision $VERSION $NO_CACHE
- %PCD_MAP $PCD_SCALE $read_in $last_pos *imagemagick_size);
+ %PCD_MAP $PCD_SCALE $read_in $last_pos );
BEGIN
{
@@ -39,34 +39,6 @@
$revision = q$Id: Size.pm,v 1.35 2003/07/21 06:48:47 rjray Exp $;
$VERSION = "2.992";
- # Check if we have Image::Magick available
- eval {
- local $SIG{__DIE__}; # protect against user installed die handlers
- require Image::Magick;
- };
- if ($@) {
- *imagemagick_size =
- sub
- {
- (undef, undef, "Data stream is not a known image file format");
- };
- } else {
- *imagemagick_size =
- sub
- {
- my ($file_name) = @_;
- my $img = Image::Magick->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'));
- }
- };
- }
-
}
# This allows people to specifically request that the cache not be used
@@ -260,6 +232,55 @@
return (wantarray) ? ($x, $y, $id) : ();
}
+sub imagemagick_size {
+ 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 ($file_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;
+ eval {
+ local $SIG{__DIE__};
+ require $module_name;
+ };
+ return !$@;
+}
+
+
sub html_imgsize
{
my @args = imgsize(@_);
diff -rN -u Image-Size-2.992-old/t/magick.t Image-Size-2.992-new/t/magick.t
--- Image-Size-2.992-old/t/magick.t 1969-12-31 19:00:00.000000000 -0500
+++ Image-Size-2.992-new/t/magick.t 2005-02-07 22:24:28.000000000 -0500
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+
+# Tests related to Image::Magick and Graphics::Magick
+
+
+BEGIN: {
+ use Test::More tests => 2;
+ use_ok('Image::Size');
+}
+
+# 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'}";
+
+
+
+
+