?
2011-12-21 04:09:55 UTC
What should be the sequence of commands?
// create a blank image:
$avatar_img = imagecreatetruecolor (AVATARWIDTH, AVATARHEIGHT); // blank image
$trp = imagecolorallocate($avatar_img, 0, 0, 0);
ImageColorTransparent($avatar_img, $trp);
ImageAlphaBlending($avatar_img, false);
// fill a background:
$grey = imagecolorallocate($avatar_img, 200, 200, 200);
imagefilledrectangle ($avatar_img, 0, 0, AVATARWIDTH -1, AVATARHEIGHT -1, $grey);
// the image is a plain grey.
// get the image that contains transparencies:
$base_avatar_img = imagecreatefrompng($fname);
imagecolortransparent($base_avatar_img, ImageColorAllocate($base_avatar_img, 0, 0, 0));
ImageAlphaBlending($base_avatar_img, false);
// merge:
imagecopyresampled ($avatar_img, $base_avatar_img, 0, 0, 0, 0, AVATARWIDTH -1, AVATARHEIGHT -1, AVATARWIDTH -1, AVATARHEIGHT -1);
imagepng($avatar_img,"avatar.png");
imagedestroy($avatar_img);
=> the grey background has disappeared...
What have I forgotten?
(same results with imagecopymerge ($avatar_img, $base_avatar_img, 0, 0, 0, 0, AVATARWIDTH -1, AVATARHEIGHT -1, 100);