Can PNG image transparency be preserved when using PHP’s GDlib imagecopyresampled?

Mar 12, 2012   //   by phpfreelancer.biz   //   Blog, PHP Tutorial  //  No Comments

The PHP code uses GD to resize a browser-uploaded PNG to 128×128. It works great, except that the transparent areas in the original image are being replaced with a solid color- black in my case.

Even though imagesavealpha is set, something isn’t quite right.

What’s the best way to preserve the transparency in the resampled image?

imagealphablending( $targetImage, false );
imagesavealpha( $targetImage, true );

did it for me.

Leave a comment

Share This Post

RSS Wordpress News