This article mainly introduces PHP using Imagecopymerge () function to create a translucent watermark, with a certain reference value, interested in small partners can refer to, hope to help everyone.
Use the Imagecopymerge () function to create a translucent watermark for everyone's reference, as follows
<?php//load the image to be watermarked $im = imagecreatefromjpeg (' photo.jpeg ');//First we manually create a watermark image from GD $stamp = imagecreatetruecolor (100, 70); Imagefilledrectangle ($stamp, 0, 0, 0x0000FF), Imagefilledrectangle ($stamp, 9, 9, 0xFFFFFF), Imagestring ($ Stamp, 5, D, ' libgd ', 0x0000FF), Imagestring ($stamp, 3,, ' (c) 2007-9 ', 0x0000FF);//Set the location and size of the watermark image $marge_right = $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 release Put memory imagepng ($im, ' photo_stamp.png '); Imagedestroy ($im);? >
Translucent watermark:
This example uses the Imagecopymerge () function to combine the watermark image with the original image. We can control the transparency of the watermark, which in this case is 50% transparency. In actual use, the use of translucent watermark can not affect the user to view the image under the premise of copyright protection.