-
-
Save yappo/100297 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use autodie; | |
use Imager; | |
use GD; | |
use Image::Magick; | |
print "# Imager $Imager::VERSION\n"; | |
print "# GD $GD::VERSION\n"; | |
print "# Image::Magick $Image::Magick::VERSION\n"; | |
my $srcfile = 'orig.jpg'; | |
for my $qtype (qw/normal mixing preview/) { | |
imager($qtype); | |
} | |
for my $method (qw/copyResized copyResampled/) { | |
gd($method); | |
} | |
imagemagick(); | |
# Imager ver. | |
# see Imager::Transformations | |
sub imager { | |
my $qtype = shift or die; # normal, mixing, preview is available. | |
my $img = Imager->new; | |
$img->read(file => $srcfile) or die; | |
my $scaled = $img->scale(xpixels => 240, ypixels => 180, qtype => $qtype) or die; | |
$scaled->write(file => "imager-$qtype.jpg", type => 'jpeg') or die; | |
} | |
sub gd { | |
my $method = shift or die; # copyResized or copyResampled | |
my $gd = GD::Image->new($srcfile) or die; | |
my $scaled = GD::Image->new(240, 180); | |
$scaled->$method( $gd, 0,0,0,0, 240,180, $gd->width,$gd->height); | |
open my $fh, '>', "gd-$method.jpg"; | |
print $fh $scaled->jpeg; | |
close $fh; | |
} | |
sub imagemagick { | |
my $img = Image::Magick->new; | |
$img->Read($srcfile); | |
my ($width, $height) = $img->Get('width', 'height'); | |
$img->Resize( | |
width => 240, | |
height => 180, | |
); | |
$img->Write('imagemagick.jpg'); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment