Well, late night at the end of the weekend, and I am in a talking to myself mood. Plus I don’t want to forget this when I wake up and actually start work tomorrow. I suppose there is always the option of doing both, depending on whether we can make a good guess as to whether or not the watermark image has alpha transparency. Still not perfect, though, like the current lib method, as if you have solid pixels at (4, 4) it won’t get it right.
// Set RGB values for text and shadow
$rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp);
$alpha = ($rgba & 0x7F000000) >> 24;
// if there's an alpha value > 0, we know we have a PNG-24
if ($alpha > 0)
{
imagecopy($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height);
}
else
{
imagecolortransparent($wm_img, $rgba);
imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity);
}