Home  >  Article  >  Backend Development  >  Detailed explanation of the steps to create a translucent watermark using the imagecopymerge() function

Detailed explanation of the steps to create a translucent watermark using the imagecopymerge() function

php中世界最好的语言
php中世界最好的语言Original
2018-05-19 14:11:321702browse

This time I will bring you a detailed explanation of the steps to create a translucent watermark with the imagecopymerge() function. What are the precautions for creating a translucent watermark with the imagecopymerge() function? Here are practical cases, let’s take a look.

<?php
// 加载要加水印的图像
$im = imagecreatefromjpeg(&#39;photo.jpeg&#39;);
// 首先我们从 GD 手动创建水印图像
$stamp = imagecreatetruecolor(100, 70);
imagefilledrectangle($stamp, 0, 0, 99, 69, 0x0000FF);
imagefilledrectangle($stamp, 9, 9, 90, 60, 0xFFFFFF);
imagestring($stamp, 5, 20, 20, &#39;libGD&#39;, 0x0000FF);
imagestring($stamp, 3, 20, 40, &#39;(c) 2007-9&#39;, 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, &#39;photo_stamp.png&#39;);
imagedestroy($im);
?>
Semi-transparent watermark:

This 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.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of the steps to convert an array using foreach in PHP

How to deal with errors when accessing array elements in double quotes in php

The above is the detailed content of Detailed explanation of the steps to create a translucent watermark using the imagecopymerge() function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn