This seems to be a common question, but trying all the combinations, I have found, it still is not working for me.
My PNG watermark is transparent and I wish to overlay the original JPG with this watermark and add a 50% opacity to the watermark.
The watermark is added and the opacity created, but the transparency of the PNG is rendered as opaque white.
I have seen examples using imagecopy()
but that function does not have the option to add opacity.
My code is as follows:
<?php
$file = 'orgCar.jpg';
$newfile = 'newCar.jpg';
if (!copy($file, $newfile)) {
echo "failed to copy $file...\n";
}
$tempIMG = imagecreatefromjpeg($newfile);
$wmkIMG = imagecreatefrompng('wmark.png');
imagealphablending($wmkIMG,true);
imagecopymerge($tempIMG, $wmkIMG, 755, 864, 0, 0, 465, 36, 50);
// Save the image to file and free memory
imagejpeg($tempIMG,'newWM.jpg');
imagedestroy($orgIMG);
imagedestroy($wmkIMG);
echo '<h3>Testing of Watermarking</h3>';
echo '<div>';
echo '<img width="160" src="orgCar.jpg" title="original" alt"" />';
echo '<img width="160" src="newCar.jpg" title="copy" alt"" />';
echo '<img width="240" src="wmark.png" title="watermark" alt"" /><br>';
echo '<img width="640" src="newWM.jpg" title="New with Watermark" alt"" />';
echo '</div>';
?>
If there is a simple answer, I have overlooked, then I would be very grateful, if someone could point me to it.