This article mainly introduces how PHP uses the imagecopymerge() function to create a translucent watermark, which has certain reference value. Interested friends can refer to it
Using the imagecopymerge() function to create a translucent watermark , for your reference, the specific content is as follows
<?php // 加载要加水印的图像 $im = imagecreatefromjpeg('photo.jpeg'); // 首先我们从 GD 手动创建水印图像 $stamp = imagecreatetruecolor(100, 70); imagefilledrectangle($stamp, 0, 0, 99, 69, 0x0000FF); imagefilledrectangle($stamp, 9, 9, 90, 60, 0xFFFFFF); imagestring($stamp, 5, 20, 20, 'libGD', 0x0000FF); imagestring($stamp, 3, 20, 40, '(c) 2007-9', 0x0000FF); // 设置水印图像的位置和大小 $marge_right = 10; $marge_bottom = 10; $sx = imagesx($stamp); $sy = imagesy($stamp); // 以 50% 的透明度合并水印和图像 imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50); // 将图像保存到文件,并释放内存 imagepng($im, 'photo_stamp.png'); imagedestroy($im); ?>
Semi-transparent watermark:
this The example uses the imagecopymerge() function to merge the watermark image and the original image. We can control the transparency of the watermark, in this case 50% transparency. In actual use, the use of translucent watermarks can protect copyright without affecting users' viewing of images.
The above is the entire content of this article. I hope it will be helpful to everyone's study. I also hope that everyone will support the php Chinese website.
The abilities that a mid-to-senior PHP engineer should possess
Detailed explanation of the code to implement the mysql connection pool effect in php
Detailed explanation of the use of PHP CURL and java http
The above is the detailed content of Detailed explanation of using PHP imagecopymerge() function to create translucent watermarks. For more information, please follow other related articles on the PHP Chinese website!