views:

116

answers:

1

Hello,

I've got a problem making alpha PNGs with PHP GD. I don't have imageMagik etc.

Though the images load perfectly well in-browser and in GFX programs, I'm getting problems with Flash AS3 (actionscript) understanding the files. It complains of being an unknown type. But, exporting these files from Fireworks to the same spec works fine. So I'm suggesting it's something wrong with the formatting in PHP GD.

There seems to be a number of ways of doing this, with several similar functions; so maybe this isn't right?

$image_p = imagecreatetruecolor($width_orig, $height_orig);

$image = imagecreatefrompng($filename); 

imagealphablending($image_p, false);
ImageSaveAlpha($image_p, true);
ImageFill($image_p, 0, 0, IMG_COLOR_TRANSPARENT);
imagealphablending($image_p, true);

imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width_orig, $height_orig, $width_orig, $height_orig);

imagepng($image_p, "new2/".$filename, 0);

imagedestroy($image_p);

This just takes files it's given and puts them into new files with a specified width/height - for this example it's same as original but in production it resizes, which is why I'm resampling.

+1  A: 

To keep the transparency you should do

imagealphablending($image_p, false);

instead of "true". Maybe that will solve the format problem too.

andr