I'm currently using the following function to create watermarked png images:
Code: Select all
function watermarkPNG($newname){
$img = imagecreatefrompng($newname);
imagesavealpha($img, true);
imagealphablending($img, false);
list($width, $height) = getimagesize($newname);
$watermark = imagecreatefrompng("classes/watermark.png");
//set new image height (image height + watermark height)
$newHeight = $height + 40;
//create canvas
$newImage = imagecreatetruecolor($width, $newHeight);
//calculate watermark cords
$y = $newHeight-40;
$x = ($width - 200)/2;
//makes $newImage background transparent
$transparent = imagecolorallocatealpha($newImage, 0, 0, 0, 127);
imagefill($newImage, 0, 0, $transparent);
ImageAlphaBlending($newImage, false);
ImageSaveAlpha($newImage, true);
//choose RGB color
//$white = imagecolorallocate($newImage,233,234,235);
//fill canvas
//imagefill($newImage,0,$y,$white);
imagecopymerge($newImage, $img, 0, 0, 0, 0, $width, $height, 100);
imagecopymerge($newImage, $watermark, $x, $y, 0, 0, 200, 40, 100);
//saves file
imagepng($newImage, $newname);
imagedestroy($img);
imagedestroy($newImage);
imagedestroy($watermark);
}