Here is the code necessary to superimpose one image (image02.png) over the top of a second (image01.png).
<?
$img1 = ImageCreateFromPNG('image01.png');
$img2 = ImageCreateFromPNG('image02.png');
ImageCopyMerge($img1, // Destination image
$img2, // Image added to destination
100, // X Coord in img1 for placing img2
150, // Y Coord in img1 for placing img2
0, // X Coord for img2 bounding box start
0, // Y Coord for img2 bounding box start
ImageSx($img2), // X Coord for img2 bounding box end
ImageSy($img2), // Y Coord for img2 bounding box end
100); // Opacity percentage (100 is opaque)
header('Content-Type: image/jpeg');
ImageJPEG($img1,'',90);
destroyImage($img1);
destroyImage($img2);
?>
Quick rundown of the code here. You take the entire secondary image (img2) or a portion of it, depending on the bounding box you create by the last two coordinate pairs in the function call. That portion of the secondary image then gets superimposed onto the first image with its upper-left corner located at the position specified by the function's first coordinate pair. You can then adjust the opacity of the second image to let the initial image show through.
This code works fairly well and with good results, however, I have not found a way to copy the secondary image over the initial image while retaining the transparency of the secondary image. i.e. I have not been able to mask off any of the secondary image when copying. If anyone has any suggestions on this I'd appreciate it.