This patch fixes a problem with imagecopyresampled() when copying an image with a non-constant alpha layer. If nobody objects, I'll commit this.
Tim
Index: gd.c =================================================================== RCS file: /repository/php4/ext/gd/libgd/gd.c,v retrieving revision 1.15 diff -u -r1.15 gd.c --- gd.c 22 Aug 2002 16:21:32 -0000 1.15 +++ gd.c 29 Sep 2002 06:36:35 -0000 @@ -2038,6 +2038,7 @@ float sx, sy; float spixels = 0.0f; float red = 0.0f, green = 0.0f, blue = 0.0f, alpha = 0.0f; + float alpha_factor, alpha_sum = 0.0f, contrib_sum = 0.0f; sy1 = ((float)(y - dstY)) * (float)srcH / (float)dstH; sy2 = ((float)(y + 1 - dstY)) * (float) srcH / @@ -2095,10 +2096,13 @@ src, (int) sx + srcX, (int) sy + srcY); - red += gdTrueColorGetRed (p) * pcontribution; - green += gdTrueColorGetGreen (p) * pcontribution; - blue += gdTrueColorGetBlue (p) * pcontribution; + alpha_factor = ((gdAlphaMax - gdTrueColorGetAlpha(p))) * pcontribution; + red += gdTrueColorGetRed (p) * alpha_factor; + green += gdTrueColorGetGreen (p) * alpha_factor; + blue += gdTrueColorGetBlue (p) * alpha_factor; alpha += gdTrueColorGetAlpha (p) * pcontribution; + alpha_sum += alpha_factor; + contrib_sum += pcontribution; spixels += xportion * yportion; sx += 1.0f; } @@ -2113,6 +2117,13 @@ blue /= spixels; alpha /= spixels; } + if ( alpha_sum != 0.0f) + { + if( contrib_sum != 0.0f ) alpha_sum /= contrib_sum; + red /= alpha_sum; + green /= alpha_sum; + blue /= alpha_sum; + } /* Clamping to allow for rounding errors above */ if (red > 255.0f) {
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php