=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];
close OUT;
sub rescale {
+ no locale;
my ($name,$out_dir,$maxsize,$info) = @_;
my ($w,$h) = dim($info);
if ($w<$maxsize && $h<$maxsize) {
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;