right. i've got it to work by going round the houses - starting with a blank 24 bit png (cheers arun_desh) and then converting it to an 8 bit png.
the code is thus:
function mergePix($sourcefile, $insertfile, $targetfile)
{
// create a 24 bit blank image with a white background
$base = ImageCreateTrueColor(50, 75);
$white = ImageColorAllocate($base, 255, 255, 255);
// tell it to respect transparency
ImageAlphaBlending($base, true);
// get pointers for files to be inserted (both 24 bit images)
$sourcefile_id = ImageCreateFromPNG($sourcefile);
$insertfile_id = ImageCreateFromPNG($insertfile);
// insert them. could use an array and a while loop instead.
ImageCopy($base, $insertfile_id, 0, 0, 0, 0, 50, 75);
ImageCopy($base, $sourcefile_id, 0, 0, 0, 0, 50, 75);
// convert it all to 8 bit with a 256 colour palette
ImageTrueColorToPalette($base, false, 256);
// loose the white background
$thecolour = ImageColorClosest($base, 255, 255, 255);
ImageColorTransparent($base, $thecolour);
// save it
ImagePNG($base, $targetfile);
// clean up
ImageDestroy($base);
ImageDestroy($sourcefile_id);
ImageDestroy($insertfile_id);
}
not very elegant at all. there must be a better way to do this and there probably is but it's gone 5am and i'm off to bed...