Image-Thumbnail

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

	last;
	use ExtUtils::Manifest ;
	ExtUtils::Manifest::mkmanifest();
	exit;
}

use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.

my @m = qw( Imager GD Image::Magick Image::Epeg);

print "This module requires at least one of: ", join(",",@m),"...\n";

foreach (@m){
	print "Looking for $_ ... ";
	eval "require "."$_";
	if ($@){
		print "not found\n";
	} else {
		print "ok\n";
		$ok = 1;
		last;
	}
}


if (not $ok){
	print <<_STOP_

This module requires you have installed on your system
one of either the GD, Imager, or Image::Magick Perl modules.

It appears you have none of these.

If you feel this message to be in error, please contact
Lee, at LGoddard-at-CPAN-dot-org.

_STOP_

} else {
	WriteMakefile(

README  view on Meta::CPAN

            my $t = new Image::Thumbnail(
                    size       => 55,
                    create     => 1,
                    input      => 'test.jpg',
                    outputpath => 'test_t.jpg',
            );

            my $t = new Image::Thumbnail(
                    size       => "55x75",
                    create     => 1,
                    module     => "Image::Magick",
                    input      => $imageObject,
                    outputpath => 'test_t.jpg',
            );

            # Create a thumbnail from 'test.jpg' as 'test_t.jpg'
            # using GD.
            my $t = new Image::Thumbnail(
                    module     => 'GD',
                    size       => 55,
                    create     => 1,

README  view on Meta::CPAN

DESCRIPTION
    This module was created to answer the FAQ, 'How do I simply create a
    thumbnail with pearl?' (*sic*). It allows you to easily make thumbnail
    images from files, objects or 'blobs', using either the ImageMagick,
    Imager or GD libraries.

    Thumbnails created can either be saved as image files or accessed as
    objects via the "object" field: see create.

PREREQUISITES
    One of "Image::Magick", "Imager", or "GD".

CONSTRUCTOR new
    Parameters are supplied as a hash or hash-like list of name/value pairs:
    See the "SYNOPSIS".

  REQUIRED PARAMETERS
    size
        The size you with the longest side of the thumbnail to be. This may
        be provided as a single integer, or as an ImageMagick-style
        'geometry' such as "100x120".

README  view on Meta::CPAN


        Returns c<undef> on failure.

EXPORT
        None.

CHANGES
        Please see the file CHANGES in the distribution tar.

SEE ALSO
        perl, Image::Epeg, GD, Imager, Image::Magick,
        Image::Magick::Thumbnail, Image::GD::Thumbnail.

AUTHOR
        Lee Goddard <cpan-at-leegoddard-dot-net>

        Thanks to Sam Tregar, Himmy and Chris Laco.

COPYRIGT
        Copyright (C) Lee Godadrd 2001-2005. All rights reserved. Supplied
        under the same terms as Perl itself.

lib/Image/Thumbnail.pm  view on Meta::CPAN

		size       => 55,
		create     => 1,
		input      => 'test.jpg',
		outputpath => 'test_t.jpg',
	);

	# With Image Magick
	my $t = new Image::Thumbnail(
		size       => "55x75",
		create     => 1,
		module	   => "Image::Magick",
		input      => $imageObject,
		outputpath => 'test_t.jpg',
	);

	# Create a thumbnail from 'test.jpg' as 'test_t.jpg'
	# using GD.
	my $t = new Image::Thumbnail(
		module     => 'GD',
		size       => 55,
		create     => 1,

lib/Image/Thumbnail.pm  view on Meta::CPAN

C<Image::Epeg>, Imager or GD libraries.

Thumbnails created can either be saved as image files or accessed as objects
via the C<object> field: see L</create>.

In the experience of the author, thumbnails are created fastest
with direct use of the L<Image::Epeg> module.

=head1 PREREQUISITES

One of C<Image::Magick>, C<Imager>, L<Image::Epeg>, or C<GD>.

=head1 CONSTRUCTOR new

Parameters are supplied as a hash or hash-like list of name/value pairs:
See the L</SYNOPSIS>.

=head2 REQUIRED PARAMETERS

=over 4

lib/Image/Thumbnail.pm  view on Meta::CPAN

The formerly required input fields should be considered depricated,
and although they will be kept in the API for this release, they will eventually
be removed.

=back

=head2 OPTIONAL PARAMETERS

=over 4

=item module ( GD | Image::Magick | Imager | Image::JPEG)

If you wish to use a specific module, place its name here.
You must have the module you require already installed!

Supplying no name will allow ImageMagick, then Imager to be tried before GD.

=item create

Put any value in this field if you wish the constructor to
call the C<create> method automatically before returning.

lib/Image/Thumbnail.pm  view on Meta::CPAN

			}
		}
		else {
			$self->{inputpath} = $self->{input}
		}
	}

	croak "You cannot supply both an 'object' field and a 'inputpath' field" if $t>1;
	croak "You must supply either an 'object' field or a 'inputpath' field"  if $t==0;

	# Try not to limit Image::Magick...
	if ($self->{inputpath}
	and $self->{module} and $self->{module} =~ /^(GD|GD::Image)$/
	and not -e $self->{inputpath}){
		croak "The supplied inputpath '$self->{inputpath}' does not exist:\n$!"
	}

	# Correct common user errors
	if ($self->{module} and $self->{module} =~ /^ImageMagick$/i){
		$self->{module} = 'Image::Magick';
		warn "Corrected parameter 'module' from 'ImaegMagick' to 'Image::Magick'" if $self->{CHAT};
	}

	# Sort out the Thumbnail module
	if (not $self->set_mod){
		$self->{error} = "No module found with which to make a thumbnail";
		warn $self->{error};
		return undef;
	}

	# Call 'create' if requested

lib/Image/Thumbnail.pm  view on Meta::CPAN

	if (not $self->{module} and $self->{object}){
		$self->{module} = ref $self->{object};
		warn "Set module to match the supplied object: $self->{module}" if $self->{CHAT};
	}

	elsif ($try){
		$self->{module} = $try;
	}

	elsif (not $self->{module} and not $try){
		for (qw( Image::Epeg Image::Magick Imager GD )){
			warn "# Try $_" if $self->{CHAT};
			if (not $self->set_mod($_)){
				next;
				return undef;
			} else {
				warn "# Set $_" if $self->{CHAT};
				last;
			}
		}
		warn "# Using ".$self->{module} if $self->{CHAT};

lib/Image/Thumbnail.pm  view on Meta::CPAN

		warn "# Requiring GD" if $self->{CHAT};
		eval { require GD };
		if ($@){
			$self->{error} = "Error requring GD:\n".$@;
			return undef;
		}
		import GD;
		warn "# GD OK" if $self->{CHAT};
	}

	elsif ($self->{module} eq 'Image::Magick'){
		warn "# Requiring Image::Magick" if $self->{CHAT};
		eval { require Image::Magick };
		if ($@){
			$self->{error} = "Error requring Image::Magick:\n".$@;
			return undef;
		}
		import Image::Magick;
		warn "# Image::Magick OK" if $self->{CHAT};
	}

	elsif ($self->{module} eq 'Imager'){
		warn "# Requiring Imager ..." if $self->{CHAT};
		eval { require Imager };
		if ($@){
			$self->{error} = "Error requring Imager:\n".$@;
			return undef;
		}
		if (defined $self->{object}->{ERRSTR} and $self->{object}->{ERRSTR} ne ''){

lib/Image/Thumbnail.pm  view on Meta::CPAN

Returns c<undef> on failure.

=cut

sub create { my $self = shift;
	my $r;
	warn "# Creating thumbnail" if $self->{CHAT};
	if ($self->{module} eq 'Image::Epeg'){
		$r = $self->create_epeg;
	} 
	elsif ($self->{module} eq 'Image::Magick'){
		$r = $self->create_imagemagick;
	} 
	elsif ($self->{module} eq 'Imager'){
		$r = $self->create_imager;
	} 
	elsif ($self->{module} =~ /^(GD|GD::Image)$/){
		$r = $self->create_gd;
    } 
    else {
		$self->{error} = "User supplied unknown module ".$self->{module};

lib/Image/Thumbnail.pm  view on Meta::CPAN

		$r = undef;
	}
	return $r;
}


#
# METHOD create_imagemagick
#
sub create_imagemagick { my $self=shift;
	warn "#...with Image::Magick" if $self->{CHAT};
	if (not $self->{object} or ref $self->{object} ne 'Image::Magick'){
		warn "#...from file $self->{inputpath}" if $self->{CHAT};
		$self->{object} = Image::Magick->new;
		if ($self->{inputblob}) {
			$self->{object}->BlobToImage( ${$self->{input}} );
		}
		elsif ($self->{inputpath}){
			$self->{error} = $self->{object}->Read($self->{inputpath});
			if ($self->{error}){
				$self->{error} = $self->{error} if $self->{CHAT};
				return undef;
			}
		}

lib/Image/Thumbnail.pm  view on Meta::CPAN

			return undef;
		}
	}
	return undef unless $self->imagemagick_thumb;

	if ($self->{outputpath}){
		warn "# Writing to $self->{outputpath}" if $self->{CHAT};
		$_ = $self->{object}->Write($self->{outputpath});
		$self->set_errors($_);
	}
	warn "# Done Image::Magick: ",$self->{x}," ",$self->{y} if $self->{CHAT};
	return 1;
}

#
# METHOD create_gd
#
sub create_gd { my $self=shift;
	local (*IN, *OUT);
	warn "# ... with GD" if $self->{CHAT};

lib/Image/Thumbnail.pm  view on Meta::CPAN

	$self->{object} = $self->{object}->scale(xpixels=>$self->{x},ypixels=>$self->{y},type=>'min');

	return 1;
}


#
# For PerlMagick: Interpret $s for errors and put in warnings/errors field
#
sub set_errors { my ($self,$s) = (shift,shift);
	if ($self->{module} eq 'Image::Magick'){
		if ($s =~ /(\d+)/){
			if ($1 <400){
				$self->{warning}  = $s;
			} else {
				$self->{error} = $s;
			}
		}
	}
}

lib/Image/Thumbnail.pm  view on Meta::CPAN

=head1 CHANGES

Please see the file F<CHANGES> included with the distribution.

=head1 SEE ALSO

L<perl>,
L<Image::Epeg>,
L<GD>,
L<Imager>,
L<Image::Magick>,
L<Image::Magick::Thumbnail>,
L<Image::GD::Thumbnail>,
L<Image::Epeg>.

=head1 AUTHOR

Lee Goddard <cpan-at-leegoddard-dot-net>

Thanks to Sam Tregar, Himmy and Chris Laco.

=head1 COPYRIGT

t/imblob.t  view on Meta::CPAN

# imblob - Test ImageMagick blobs
our $VERSION = sprintf("%d.%02d", q$Revision: 0.01 $ =~ /(\d+)\.(\d+)/);

use lib "../lib";
use strict;
use Test::More;

use Cwd;
BEGIN {
	eval'use Image::Magick';
	if ( $@) {
		 plan skip_all => "Skip IM tests - IM not installed";
	} else {
		plan tests => 7;
	}
	use_ok ("Image::Thumbnail" => 0.62);
}

my $cwd = cwd."/";
$cwd .= 't/' if $cwd !~ /[\\\/]t[\\\/]?$/;

t/imblob.t  view on Meta::CPAN

#	CHAT=>1,
	size		=> 55,
	create		=> 1,
	input		=> \$blob,
	outputpath	=> $cwd.'/test_t.jpg',
);

warn "# ".$t->{error} if $t->{error};

isa_ok($t, "Image::Thumbnail");
isa_ok($t->{object}, "Image::Magick");

ok ( defined $t->{x}, "defined x");
ok ( $t->{x}==55, "correct x");
ok ( $t->{y}==48, "correct y");
unlink($cwd."t/test_t.jpg");

t/imf.t  view on Meta::CPAN

# imf - Test ImageMagick to/from file
our $VERSION = sprintf("%d.%02d", q$Revision: 0.03 $ =~ /(\d+)\.(\d+)/);

use lib "../lib";
use strict;
use Test::More;

use Cwd;

BEGIN {
	eval'use Image::Magick';
	if ( $@) {
		 plan skip_all => "Skip IM tests - IM not installed";
	} else {
		plan tests => 7;
	}
}

use_ok ("Image::Thumbnail" => 0.62);

my $cwd = cwd."/";

t/imf.t  view on Meta::CPAN

#	CHAT=>1,
	size=>55,
	create=>1,
	input => $cwd.'test.jpg',
	outputpath => $cwd.'/test_t.jpg',
);

warn "# ".$t->{error} if $t->{error};

isa_ok($t, "Image::Thumbnail");
isa_ok($t->{object}, "Image::Magick");

ok ( defined $t->{x}, "defined x");
ok ( $t->{x}==55, "correct x");
ok ( $t->{y}==48, "correct y");
unlink($cwd."t/test_t.jpg");

t/imfa.t  view on Meta::CPAN

use strict;
our $VERSION = sprintf("%d.%02d", q$Revision: 0.03 $ =~ /(\d+)\.(\d+)/);



BEGIN {
	use lib "..";
	use Test::More;
	use Cwd;

	eval'use Image::Magick';
	if ( $@) {
		 plan skip_all => "Skip IM tests - IM not installed";
	} else {
		plan tests => 6;
	}
	use_ok ("Image::Thumbnail");
}

my $cwd = cwd."/";
$cwd .= 't/' if $cwd !~ /[\\\/]t[\\\/]?$/;

t/imfa.t  view on Meta::CPAN

	inputpath=>$cwd.'/test.jpg',
	outputpath=>$cwd.'/test_t.jpg',
	attr=> {
		antialias => 'true',
	}
);

warn "# ".$t->{error} if $t->{error};

isa_ok($t, "Image::Thumbnail");
isa_ok($t->{object}, "Image::Magick");

ok ( defined $t->{x}, "x defined");
ok ( $t->{x}==55, "correct x");
ok ( $t->{y}==48, "correct y");
unlink($cwd."t/test_t.jpg");

t/imo.t  view on Meta::CPAN

# imf - Test ImageMagick from object
use strict;
our $VERSION = sprintf("%d.%02d", q$Revision: 0.03 $ =~ /(\d+)\.(\d+)/);
use Test::More;

BEGIN {
	use Cwd;
	use lib "..";
	eval'require Image::Magick';
	if ( $@) {
		 plan skip_all => "Skip Image Magick tests - IM not installed";
	} else {
		plan tests => 4;
	}
}

use_ok("Image::Thumbnail");

my $cwd = cwd."/";
$cwd .= 't/' if $cwd !~ /[\\\/]t[\\\/]?$/;

my $img = new Image::Magick;

$img->Read($cwd.'test.jpg');

my $t = new Image::Thumbnail(
#	CHAT=>1,
	object=>$img,
	size=>55,
	create=>1,
	outputpath=>$cwd.'/test_t.jpg',
);



( run in 0.678 second using v1.01-cache-2.11-cpan-beeb90c9504 )