From: Victor Wagner Date: Sun, 13 Mar 2016 14:51:46 +0000 (+0300) Subject: Moved from imagemagick to netpbm for scaling X-Git-Url: http://wagner.pp.ru/gitweb/?a=commitdiff_plain;ds=inline;p=oss%2Fimgwww.git Moved from imagemagick to netpbm for scaling --- diff --git a/imagedir b/imagedir index 3ca9403..dbcde4b 100755 --- a/imagedir +++ b/imagedir @@ -58,6 +58,8 @@ Title. If none given, directory name is used. =cut use vars qw($opt_t $opt_n $opt_l $opt_f); +our %decoders=('image/gif'=>'giftopnm','image/tiff'=>'tifftopnm','image/jpeg'=>'djpeg'); + getopts("t:lnf"); my $dir = $opt_t || (split ("/",cwd()))[-1]; @@ -103,6 +105,7 @@ print OUT "\n"; close OUT; sub rescale { + no locale; my ($name,$out_dir,$maxsize,$info) = @_; my ($w,$h) = dim($info); if ($w<$maxsize && $h<$maxsize) { @@ -110,10 +113,21 @@ sub rescale { return $name; } my $result = "$out_dir/$name"; + $result .= ".jpg" unless $result=~/\.jpe?g$/i; if ( ! -f $result || -M $name < -M $result) { print STDERR " $out_dir..."; - - system "convert", "-geometry", $maxsize."x".$maxsize,$_,$result; + my $scale; + if ($w > $h) { + $scale = $maxsize*1.0/$w; + } else { + $scale = $maxsize*1.0/$h; + } + my $ftype= $info->{file_media_type}; + die "Unknown image type for $name: $ftype\n" + if (not exists $decoders{$ftype}); + my $decoder=$decoders{$ftype}; + system "$decoder \"$name\" | pnmscale -xscale ". $scale . " -yscale " . + "$scale |cjpeg > $result"; print STDERR "\b\b\b "; } return $result;