diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c index 7831254b91e5..63eb02d6af37 100644 --- a/ext/gd/libgd/gd.c +++ b/ext/gd/libgd/gd.c @@ -2612,7 +2612,6 @@ void gdImageCopyResampled (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, i green /= spixels; blue /= spixels; alpha /= spixels; - alpha += 0.5; } if ( alpha_sum != 0.0f) { if( contrib_sum != 0.0f) { @@ -2622,20 +2621,12 @@ void gdImageCopyResampled (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, i green /= alpha_sum; blue /= alpha_sum; } - /* Clamping to allow for rounding errors above */ - if (red > 255.0f) { - red = 255.0f; - } - if (green > 255.0f) { - green = 255.0f; - } - if (blue > 255.0f) { - blue = 255.0f; - } - if (alpha > gdAlphaMax) { - alpha = gdAlphaMax; - } - gdImageSetPixel(dst, x, y, gdTrueColorAlpha ((int) red, (int) green, (int) blue, (int) alpha)); + /* Round up closest next channel value and clamp to max channel value */ + red = red >= 255.5 ? 255 : red+0.5; + blue = blue >= 255.5 ? 255 : blue+0.5; + green = green >= 255.5 ? 255 : green+0.5; + alpha = alpha >= gdAlphaMax+0.5 ? 255 : alpha+0.5; + gdImageSetPixel(dst, x, y, gdTrueColorAlpha ((int)red, (int)green, (int)blue, (int)alpha)); } } } diff --git a/ext/gd/libgd/gd_png.c b/ext/gd/libgd/gd_png.c index f628d876ef5e..996e86ae754f 100644 --- a/ext/gd/libgd/gd_png.c +++ b/ext/gd/libgd/gd_png.c @@ -728,12 +728,7 @@ void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level, int basefilte */ a = gdTrueColorGetAlpha(thisPixel); /* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */ - if (a == 127) { - *pOutputRow++ = 0; - } else { - *pOutputRow++ = 255 - ((a << 1) + (a >> 6)); - } - + *pOutputRow++ = 255 - ((a << 1) + (a >> 6)); } } } diff --git a/ext/gd/tests/bug53580.phpt b/ext/gd/tests/bug53580.phpt new file mode 100644 index 000000000000..86872f6c1b5f --- /dev/null +++ b/ext/gd/tests/bug53580.phpt @@ -0,0 +1,32 @@ +--TEST-- +Bug #53580 (During resize gdImageCopyResampled cause colors change) +--SKIPIF-- + 2.3.2"); +} +?> +--FILE-- + +--EXPECT--