This example for you to share the PHP use of the GD library for the image of the method of adding watermarks for your reference, the specific contents are as follows
<?php
$dst _path = ' 1.jpg '///target picture
$src _path = ' logo1.png ';//Watermark Picture
//Create instance of picture
$DST = Imagecreatefromstring (file_get_contents ($DST _path));
$SRC = imagecreatefromstring (file_get_contents ($src _path));
Gets the watermark picture's width high
list ($src _w, $src _h) = getimagesize ($src _path);
Copy the watermark picture to the target picture, and the last argument 50 is to set the transparency, where the translucent effect is achieved, and two 20 is the control watermark coordinates position
imagecopymerge ($DST, $SRC, m, 0, 0, $src _w, $src _h, 50) ;
If the watermark picture itself is transparent, use the Imagecopy method
//imagecopy ($DST, $SRC, ten, 0, 0, $src _w, $src _h);
Output picture
list ($dst _w, $dst _h, $dst _type) = getimagesize ($dst _path);
Switch ($dst _type) {case
1://gif
header (' content-type:image/gif ');
Imagegif ($DST);
break;
Case 2://jpg
Header (' content-type:image/jpeg ');
Imagejpeg ($DST);
break;
Case 3://png
Header (' content-type:image/png ');
Imagepng ($DST);
break;
Default: Break
;
}
Imagedestroy ($DST);
Imagedestroy ($SRC);
? >
Effect Chart:
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.