From b92216b97dcdae738ae24d9bdd1168565dc04406 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sun, 9 Oct 2016 14:59:37 +0200 Subject: [PATCH] Fix #73272: imagescale() affects imagesetinterpolation() We must not permanently change the interpolation method, but rather have to restore the old method after we're done with scaling the image. --- NEWS | 2 ++ ext/gd/gd.c | 5 ++++- ext/gd/tests/bug73272.phpt | 24 ++++++++++++++++++++++++ ext/gd/tests/bug73272.png | Bin 0 -> 739 bytes 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 ext/gd/tests/bug73272.phpt create mode 100644 ext/gd/tests/bug73272.png diff --git a/NEWS b/NEWS index e9e4b9486f7..a41168d066c 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,8 @@ PHP NEWS -GD: . Fixed bug #73213 (Integer overflow in imageline() with antialiasing). (cmb) + . Fixed bug #73272 (imagescale() is not affected by, but affects + imagesetinterpolation()). (cmb) - Standard: . Fixed bug #73203 (passing additional_parameters causes mail to fail). (cmb) diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 5f086864ca3..39cb4eb0533 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -5175,7 +5175,7 @@ PHP_FUNCTION(imagescale) gdImagePtr im_scaled = NULL; int new_width, new_height; long tmp_w, tmp_h=-1, tmp_m = GD_BILINEAR_FIXED; - gdInterpolationMethod method; + gdInterpolationMethod method, old_method; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|ll", &IM, &tmp_w, &tmp_h, &tmp_m) == FAILURE) { return; @@ -5202,9 +5202,12 @@ PHP_FUNCTION(imagescale) new_width = tmp_w; new_height = tmp_h; + /* gdImageGetInterpolationMethod() is only available as of GD 2.1.1 */ + old_method = im->interpolation_id; if (gdImageSetInterpolationMethod(im, method)) { im_scaled = gdImageScale(im, new_width, new_height); } + gdImageSetInterpolationMethod(im, old_method); if (im_scaled == NULL) { RETURN_FALSE; diff --git a/ext/gd/tests/bug73272.phpt b/ext/gd/tests/bug73272.phpt new file mode 100644 index 00000000000..3bb710cdc7d --- /dev/null +++ b/ext/gd/tests/bug73272.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #73272 (imagescale() is not affected by, but affects imagesetinterpolation()) +--SKIPIF-- + +--FILE-- + +===DONE=== +--EXPECT-- +The images are equal. +===DONE=== diff --git a/ext/gd/tests/bug73272.png b/ext/gd/tests/bug73272.png new file mode 100644 index 0000000000000000000000000000000000000000..97bfadf983e7cf9f96600b2a0bc09a105cb083f4 GIT binary patch literal 739 zcmeAS@N?(olHy`uVBq!ia0vp^?I6s-1|)5sdjTbwR(ZNOhE&XXd-rbM>;Qq*i_TZS z*QZvwc26judxUMiGF?n=D&Gw zmsUJE^lSLoa9=TnU6*10n2@3`IxdG0=0c=TY(cMY?*k0c(?>Md`7c~PrR z`~T`2am$NUbRYeA!uCqy=(4k(8~pQ^q(D}wsIOYD@Gb!5w;zO&7&aAlnMBw=BxAqs;uFH`zmdh^*HtN%Rf9B@Yp2dfbybvfj zX`!{|2N$C~P`EU9dHhdNrn+S*GRbH5e$qbjTQv3YjL7Ny59cV_I<~JgY&%)lr8jwT zj?Cu$*6H#4)@w)~Ut=|Qr>^Yrp2fSpC6Yz@liiHjeg`jo{NfAeiyp7z8)vFc@H;M@ zY+`Z#VrKH0WoMuK`10k2ndz|%q2uc2r+5=t`0wr+e?OP>CtZHl@MWUN32pJ--IK2s z=KL#vxc%``)$jc;>kj<%xy^m-