I am creating an application that will help me resize images quickly.
Some of the images I wanted to resize in in PNG format, with alpha channel, but when I resize using imagecopyresampled, the output image is not ahh, transparent anymore.
Any ideas please?
This is the way this application work: This application opens the source image, and calculate the destination size, create a new true color image, and then imagecopyresampled to the destination image resource, then write to file.
I’m not sure why none of it’s transparent, but it really doesn’t surprise me. You don’t have much control over image resizing and you need to do it in a decent graphics package if you want to keep the quality.
If you want to resize a png-24 image and preserve the alpha channel you need to set imagealphablending($im_dest, false) on the destination image just after creating it with imagecreatetruecolor() and do a imagesavealpha($im_dest, true) on it before saving it: