Php uses the gd library to add watermarks to images,
The examples in this article share with you how php uses the gd library to add watermarks to images for your reference. The specific content is as follows:
<? Php $ dst_path = '1.jpg '; // target image $ src_path = 'logo1.png'; // watermark image // create an image instance $ dst = imagecreatefromstring (file_get_contents ($ dst_path )); $ src = imagecreatefromstring (file_get_contents ($ src_path); // obtain the width and height list ($ src_w, $ src_h) = getimagesize ($ src_path ); // copy the watermark image to the target image. The last parameter is set to 50. The transparency is achieved here. The two 20 are used to control the Coordinate Position of the watermark imagecopymerge ($ dst, $ src, 20, 20, 0, 0, $ src_w, $ src_h, 50); // If the watermark image is transparent, use the imagecopy method // imagecopy ($ d St, $ src, 10, 10, 0, 0, $ src_w, $ src_h); // output image 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);?>
:
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.