Created
August 31, 2010 18:20
-
-
Save kamipo/559469 to your computer and use it in GitHub Desktop.
JPEG画像の変換(libjpeg-turboで速くなる)
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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Benchmark qw(:all); | |
use Image::Magick; | |
use Imager; | |
my $has_imlib = eval q{ use Image::Imlib2; 1 }; | |
warn "Image::Imlib2 is not available\n" if $@; | |
my $has_gd = eval q{ use GD::Image; 1 }; | |
warn "GD::Image is not available\n" if $@; | |
my $input = './images/input.jpg'; | |
my $output = './images/output.jpg'; | |
timethese 100, { | |
'Image::Magick' => sub { | |
my $img = Image::Magick->new; | |
$img->Read($input); | |
$img->Write($output); | |
}, | |
'Imager' => sub { | |
my $img = Imager->new; | |
$img->read(file => $input); | |
$img->write(file => $output); | |
}, | |
$has_imlib ? ( | |
'Image::Imlib2' => sub { | |
my $img = Image::Imlib2->new; | |
$img->load($input); | |
$img->save($output); | |
}, | |
) : (), | |
$has_gd ? ( | |
'GD::Image' => sub { | |
my $gd = GD::Image->newFromJpeg($input); | |
open my $fh, ">", $output; | |
print $fh $gd->jpeg; | |
close $fh; | |
}, | |
) : (), | |
}; |
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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Benchmark qw(:all); | |
use Image::Magick; | |
use Imager; | |
my $has_imlib = eval q{ use Image::Imlib2; 1 }; | |
warn "Image::Imlib2 is not available\n" if $@; | |
my $has_gd = eval q{ use GD::Image; 1 }; | |
warn "GD::Image is not available\n" if $@; | |
$has_gd = eval q{ use Image::Resize; 1 }; | |
warn "Image::Resize is not available\n" if $@; | |
my $input = './images/input.jpg'; | |
my $output = './images/output.jpg'; | |
my $width = 80; | |
my $height = 60; | |
timethese 100, { | |
'Image::Magick' => sub { | |
my $img = Image::Magick->new; | |
$img->Read($input); | |
#$img->Set(size => $width.'x'.$height); | |
$img->Resize(width => $width, height => $height); | |
$img->Write($output); | |
}, | |
'Imager' => sub { | |
my $img = Imager->new; | |
$img->read(file => $input); | |
my $scaled = $img->scale(xpixels => $width); | |
$scaled->write(file => $output); | |
}, | |
$has_imlib ? ( | |
'Image::Imlib2' => sub { | |
my $img = Image::Imlib2->new; | |
$img->load($input); | |
$img->create_scaled_image($width, $height); | |
$img->save($output); | |
}, | |
) : (), | |
$has_gd ? ( | |
'GD::Image' => sub { | |
my $gd = GD::Image->newFromJpeg($input); | |
my $img = Image::Resize->new($gd); | |
$gd = $img->resize($width, $height); | |
open my $fh, ">", $output; | |
print $fh $gd->jpeg; | |
close $fh; | |
}, | |
) : (), | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment