This piece explains how to create a translucent watermark using the Imagecopymerge () function in PHP.
Use the Imagecopymerge () function to create a translucent watermark for everyone's reference, as follows
Load the image you want to add a watermark to
$im = Imagecreatefromjpeg (' photo.jpeg ');
First we create the watermark image manually from GD
$stamp = Imagecreatetruecolor (100, 70); Imagefilledrectangle ($stamp, 0, 0, 0x0000FF), Imagefilledrectangle ($stamp, 9, 9, 0xFFFFFF); Imagestring ($stamp, 5, (3), ' LIBGD ', 0x0000FF), imagestring ($stamp), (c) 2007-9 ', 0x0000FF);
Set the location and size of the watermark image
$marge _right = 10; $marge _bottom = ten; $sx = Imagesx ($stamp); $sy = Imagesy ($stamp);
Combine watermarks and images with 50% transparency
Imagecopymerge ($im, $stamp, Imagesx ($im)-$sx-$marge _right, Imagesy ($im)-$sy-$marge _bottom, 0, 0, Imagesx ($stamp), Imagesy ($stamp), 50);
Save the image to a file and free up memory
Imagepng ($im, ' photo_stamp.png '); Imagedestroy ($im);?>
This article explains how PHP uses the Imagecopymerge () function to create a translucent watermark, and more about the PHP Chinese web.