| Catalyst-Plugin-Upload-Image-Magick documentation | Contained in the Catalyst-Plugin-Upload-Image-Magick distribution. |
Catalyst::Plugin::Upload::Image::Magick::Thumbnail::Fixed - Making thumbnail image is kept ratio in fixed size image.
Version 0.03
In your Catalyst project,
use Catalyst qw/Upload::Image::Magick::Thumbnail::Fixed/;
You can execute "thumbnail_fixed" method in Catalyst::Request::Upload object
sub resize_to: Local {
my ($self, $c) = @_;
my $upload = $c->request->upload('file_field');
my $thumbnail = $upload->thumbnail_fixed({
density => '60x70',
format => 'png',
quality => 100
});
# $thumbnail is Image::Magick object
my ($width, $height) = $thumbnail->Get('width', 'height');
# ...
}
Create "fixed" size thumbnail image.
$args is hash reference. Please see below arguments detail.
String formatted width x height. See below example format.
"80x60"
Number format of thumbnail width. Priority of density option is higher than width option. Default value is 60pixel.
Number format of thumbnail height. Priority of density option is higher than height option. Default value is 60pixel.
String of image format. You can choose one of gif, jpg or png.
Image quality option. highest value is 100. minimam value is 0. default 70.
See also Image::Magick::Thumbnail, Image::Magick::Thumbnail::Fixed
Toru Yamaguchi, <zigorou at cpan.org>
Please report any bugs or feature requests to
bug-catalyst-plugin-upload-image-magick-thumbnail-fixed at rt.cpan.org, or through the web interface at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Plugin-Upload-Image-Magick.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc Catalyst::Plugin::Upload::Image::Magick
You can also look for information at:
http://annocpan.org/dist/Catalyst-Plugin-Upload-Image-Magick
http://cpanratings.perl.org/d/Catalyst-Plugin-Upload-Image-Magick
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Plugin-Upload-Image-Magick
http://search.cpan.org/dist/Catalyst-Plugin-Upload-Image-Magick
Copyright 2006 Toru Yamaguchi, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Catalyst-Plugin-Upload-Image-Magick documentation | Contained in the Catalyst-Plugin-Upload-Image-Magick distribution. |
package Catalyst::Plugin::Upload::Image::Magick::Thumbnail::Fixed; use strict; use warnings; use Catalyst::Request::Upload; use Catalyst::Utils; use Catalyst::Exception; use File::Temp; use Image::Magick; use Image::Magick::Thumbnail::Fixed;
our $VERSION = '0.03';
{ package Catalyst::Request::Upload; __PACKAGE__->mk_accessors(qw/_thumbnail_fixed _thumbnail_temp/); sub thumbnail_fixed { my ( $self, $args ) = @_; Catalyst::Exception->throw( "Please require Catalyst::Plugin::Upload::Image::Magick") unless ( $self->can("is_image") ); Catalyst::Exception->throw( "This file is not image : " . $self->filename ) unless ( $self->is_image ); unless ( $self->_thumbnail_fixed ) { $self->_thumbnail_fixed( Image::Magick::Thumbnail::Fixed->new ); } if ( exists $args->{density} && $args->{density} =~ m|\d+x\d+| ) { ( $args->{width}, $args->{height} ) = map { s/\s+//g; $_ } split( /x/, $args->{density} ); delete $args->{density}; } else { $args->{width} = 60 unless ( exists $args->{width} ); $args->{height} = 60 unless ( exists $args->{height} ); } $args->{format} = "jpg" unless ( exists $args->{format} ); $args->{input} = $self->tempname; $args->{output} = File::Temp->new( DIR => Catalyst::Utils::class2tempdir( "Catalyst::Plugin::Upload::Image::Magick::Thumbnail::Fixed", 1 ), TEMPLATE => "thumbnail_XXXXXX", EXT => $args->{format} ); eval { $self->_thumbnail_fixed->thumbnail(%$args); }; if ($@) { Catalyst::Exception->throw($@); } elsif ( !-e $args->{output} ) { Catalyst::Exception->throw( "Can't create thumbnail : " . $args->{output} ); } my $thumb = Image::Magick->new; $thumb->Read( $args->{output} ); ### for File::Temp's cleanup $self->_thumbnail_temp({}) unless ($self->_thumbnail_temp); $self->_thumbnail_temp->{ $thumb->Get('filename') } = $args->{output}; return $thumb; } }
1; # End of Catalyst::Plugin::Upload::Image::Magick::Thumbnail::Fixed