- if ($params{size} ne 'full') {
- my ($w, $h) = ($params{size} =~ /^(\d+)x(\d+)$/);
- error sprintf(gettext('bad size "%s"'), $params{size})
- unless (defined $w && defined $h);
+ my ($dwidth, $dheight);
+
+ if ($params{size} eq 'full') {
+ $dwidth = $im->Get("width");
+ $dheight = $im->Get("height");
+ } else {
+ my ($w, $h) = ($params{size} =~ /^(\d*)x(\d*)$/);
+ error sprintf(gettext('wrong size format "%s" (should be WxH)'), $params{size})
+ unless (defined $w && defined $h &&
+ (length $w || length $h));
+
+ if ($im->Get("width") == 0 || $im->Get("height") == 0) {
+ ($dwidth, $dheight)=(0, 0);
+ } elsif (! length $w || (length $h && $im->Get("height")*$w > $h * $im->Get("width"))) {
+ # using height because only height is given or ...
+ # because original image is more portrait than $w/$h
+ # ... slimness of $im > $h/w
+ # ... $im->Get("height")/$im->Get("width") > $h/$w
+ # ... $im->Get("height")*$w > $h * $im->Get("width")
+
+ $dheight=$h;
+ $dwidth=$h / $im->Get("height") * $im->Get("width");
+ } else { # (! length $h) or $w is what determines the resized size
+ $dwidth=$w;
+ $dheight=$w / $im->Get("width") * $im->Get("height");
+ }
+ }
+
+ if ($dwidth < $im->Get("width") || $ispdf) {
+ # resize down, or resize to pixels at all
+
+ my $outfile = "$config{destdir}/$dir/$params{size}-$base";
+ $imglink = "$dir/$params{size}-$base";