Image::Magickã«ãããµã ãã¤ã«çæé«éå
Image::Magickã¯æ±ç¨çãªç»åå¦çãè¡ããã¨ããå©ç¹ãããããé度çã«ã¯ãã¾ãæ©ããªãã
ãã¨ãã°å¤§éã«ã¢ãããããä¸ç¼ã¬ããªã©ã§æ®å½±ãã大ããªãµã¤ãºã®JPEGãããµã ãã¤ã«ãçæããã¨ãããããªç¶æ³ã«ããã¦ã¯ãå¦çé度ãããã«ããã¯ã«ãªã£ã¦ãã¾ãã¨ããåé¡ãããã
ã¨ããããã©ãããã¤ã³ã¹ã¿ã³ã¹çææã«sizeãªãã·ã§ã³ãæå®ããã ãã§å¦çé度ãåçã«åä¸ããããããã¨ãããã¨ãåæã®ã¨ã³ã¸ãã¢raiæ°ããèããã®ã§è©¦ãã¦ã¿ãã
â ãã³ããã¼ã¯å
容
å
ç»åãï¼ http://photozou.jp/photo/show/228995/18479223
ï¼å
ç»å4272x2848ã使ç¨ãã«ã¡ã©å°å§Gããã®ç»åããåããã¾ãï¼
çæç»åï¼ æ¨ª160pxã«åºå®ããã¢ã¹ãã¯ãæ¯ãç¶æ
ãµã ãã¤ã«50æã®çææéãæ¯è¼ããã
â æ¤è¨¼ã³ã¼ã
#!/usr/bin/perl use strict; use warnings; use Benchmark qw(timethese); use Image::Magick; timethese(50, { im_normal => 'im_normal( input_file => "miko.jpg", output_file => "out_normal.jpg", width => 160, );', im_optional => 'im_optional( input_file => "miko.jpg", output_file => "out_optional.jpg", width => 160, );', }); sub im_normal { my %param = @_; my $input_file = $param{input_file}; my $output_file = $param{output_file}; my $fix_width = $param{width}; my $image = Image::Magick->new(); $image->Read($input_file); my ($width, $height) = $image->Get('width', 'height'); my $n_width = $fix_width; my $n_height = $height * ($n_width / $width); $image->Thumbnail( width => $n_width, height => $n_height ); $image->Write($output_file); return; } sub im_optional { my %param = @_; my $input_file = $param{input_file}; my $output_file = $param{output_file}; my $fix_width = $param{width}; my $image = Image::Magick->new( size => $fix_width.'x'.$fix_width ); $image->Read($input_file); my ($width, $height) = $image->Get('width', 'height'); my $n_width = $fix_width; my $n_height = $height * ($n_width / $width); $image->Thumbnail( width => $n_width, height => $n_height ); $image->Write($output_file); return; }
â å®è¡ç°å¢
Intel Core2Duo 2.6GHz ï¼ Memory 2GBãï¼ FreeBSD7.0R
â å®è¡çµæ
%perl benche.pl Benchmark: timing 50 iterations of im_normal, im_optional... im_normal: 40 wallclock secs (35.78 usr + 3.70 sys = 39.48 CPU) @ 1.27/s (n=50) im_optional: 10 wallclock secs ( 9.70 usr + 0.28 sys = 9.98 CPU) @ 5.01/s (n=50)
æ©ã£ï¼ï¼ï¼
ã¤ã³ã¹ã¿ã³ã¹çææã«å¼æ°ãå ããã ãã§é度4åã§ãã
åºåç»åã®ãµã¤ãºã決ã¾ã£ã¦ããå ´åã¯sizeãªãã·ã§ã³ãæå®ããã»ããè³¢æã§ããï¼ï¼
ã追è¨ã
åæã®hirokiæ°ã¨è©±ãã¦ãã¦åºã話é¡ã§ããsizeæå®ãããã¨ä½æ¥ç¨ãã£ã³ãã¹ã®ãµã¤ãºãéå®ãããã®ã§æ©ããªãããããï¼èªã¿è¾¼ã¿ãé«éåããããããï¼ãã¨ããæè¦ãåºãã®ã§$image->Readã®ã¿åæ¡ä»¶ä¸ã§ãã³ããã¦ã¿ãã
â å®è¡çµæ
%perl benche.pl Benchmark: timing 50 iterations of im_normal, im_optional... im_normal: 37 wallclock secs (33.87 usr + 3.30 sys = 37.17 CPU) @ 1.35/s (n=50) im_optional: 8 wallclock secs ( 7.70 usr + 0.12 sys = 7.82 CPU) @ 6.39/s (n=50)
ãããï¼ãã£ã±ãReadãæ¿éåãã¦ãï¼ï¼
éã«è¨ãã°ç¸®å°ã®è¨ç®ã³ã¹ãã£ã¦ãããªã«é«ããªãã®ãããï¼ç¬ï¼