in addition to stefan's posting:
i found that if you use imagecopymerge with png-24 files with an alpha channel, it doesn't work use imagecopy instead.
it seems that imagecopymerge doesn't respect the alpha channel the way it should (a bug??).
some sample code here to place an image (image.png) on a backgroundcolor or backgroundimage.
<?php
$im = "image.png";
$bg = "ffddee"; $out = "png"; function colordecode($hex){
$code[r] = hexdec(substr($hex, 0 ,2));
$code[g] = hexdec(substr($hex, 2 ,2));
$code[b] = hexdec(substr($hex, 4 ,2));
return $code;
} $image_id = imageCreateFromPNG($im);
$im_X = ImageSX($image_id);
$im_Y = ImageSY($image_id);
$backgroundimage = imagecreatetruecolor($im_X, $im_Y);
$code = colordecode($bg);
$backgroundcolor = ImageColorAllocate($backgroundimage, $code[r], $code[g], $code[b]);
ImageFilledRectangle($backgroundimage, 0, 0, $im_X, $im_Y, $backgroundcolor);
ImageAlphaBlending($backgroundimage, true);
imagecopy($backgroundimage, $image_id, 0, 0, 0, 0, $im_X, $im_Y);
if($output == "jpg"){
Header( "Content-type: image/jpeg");
ImageJPEG($backgroundimage);
}
else{
Header( "Content-type: image/png");
ImagePNG($backgroundimage);
}
ImageDestroy($backgroundimage);
ImageDestroy($image_id);
?>