- else {
- $r = $im->Read($srcfile);
- error sprintf(gettext("failed to read %s: %s"), $file, $r) if $r;
-
- # don't resize any larger
- my ($rw, $rh) = ($w, $h);
- if ((length $rw && $rw > $im->Get("width")) ||
- (length $rh && $rh > $im->Get("height"))) {
- $rw=$im->Get("width");
- $rh=$im->Get("height");
+
+ if (! length $w && ! length $h) {
+ $dwidth = $im->Get("width");
+ $dheight = $im->Get("height");
+ } else {
+ 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");