| CGI-Application-PhotoGallery documentation | Contained in the CGI-Application-PhotoGallery distribution. |
CGI::Application::PhotoGallery::Imager - Imager-based graphics adaptor
use CGI::Application::PhotoGallery::Imager;
my $lib = CGI::Application::PhotoGallery::Image->new;
my $pngdata = $lib->resize( $file, 100 );
creates a new CGI::Application::PhotoGallery::Imager object.
Loads $file and returns an Imager object.
Returns the width and height of $file.
Resizes $file to $sizex$size with margins.
Brian Cassidy <bricas@cpan.org>
Copyright 2003-2009 by Brian Cassidy
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| CGI-Application-PhotoGallery documentation | Contained in the CGI-Application-PhotoGallery distribution. |
package CGI::Application::PhotoGallery::Imager; use strict; use warnings; use Imager; our $VERSION = '0.15';
sub new { my $class = shift; my $self = {}; bless $self, $class; return $self; }
sub load { my $self = shift; my $file = shift; my $image = Imager->new; $image->read( file => $file ); return $image; }
sub size { my $self = shift; my $file = shift; my $image = $self->load( $file ); return $image->getwidth, $image->getheight; }
sub resize { my $self = shift; my $file = shift; my $size = shift; my $image = $self->load( $file ); my $type = $image->getwidth > $image->getheight ? 'x' : 'y'; $image = $image->scale( "${type}pixels" => $size ); my( $w, $h ) = ( $image->getwidth, $image->getheight ); my $x = $size == $w ? 0 : int( ($size - $w) / 2 ); my $y = $size == $h ? 0 : int( ($size - $h) / 2 ); my $newimage = Imager->new( xsize => $size, ysize => $size ); $newimage->paste( img => $image, left => $x, top => $y ); my $return; $newimage->write( type => 'png', data=> \$return ); return $return; }
1;