]> granicus.if.org Git - php/commitdiff
Fixed Bug #65171 imagescale() fails
authorRemi Collet <remi@php.net>
Wed, 15 Oct 2014 17:13:25 +0000 (19:13 +0200)
committerRemi Collet <remi@php.net>
Wed, 15 Oct 2014 17:13:25 +0000 (19:13 +0200)
Third param (height) is set as optional,
but default value = -1 is incorrect

Compute correct height to preserve ratio.

ext/gd/gd.c

index cbc7219e37c78f02b4a3d193190c297db92cf368..f86dad58dc2015eda8a9c6abf5810506922835d5 100644 (file)
@@ -5110,11 +5110,23 @@ PHP_FUNCTION(imagescale)
                return;
        }
        method = tmp_m;
-       new_width = tmp_w;
-       new_height = tmp_h;
 
        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
 
+       if (tmp_h < 0) {
+               /* preserve ratio */
+               long src_x, src_y;
+
+               src_x = gdImageSX(im);
+               src_y = gdImageSY(im);
+               if (src_x) {
+                       tmp_h = tmp_w * src_y / src_x;
+               }
+       }
+
+       new_width = tmp_w;
+       new_height = tmp_h;
+
        if (gdImageSetInterpolationMethod(im, method)) {
                im_scaled = gdImageScale(im, new_width, new_height);
        }