Home  >  Article  >  Backend Development  >  PHP uses the imagecopymerge() function to create a semi-transparent watermark method

PHP uses the imagecopymerge() function to create a semi-transparent watermark method

jacklove
jackloveOriginal
2018-05-22 16:00:551630browse

This video explains how to create a translucent watermark using the imagecopymerge() function through PHP.

Use the imagecopymerge() function to create a translucent watermark for your reference. The specific content is as follows

// Load the image to be watermarked

$im = imagecreatefromjpeg('photo .jpeg');

// First we manually create the watermark image from 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);

// Set the position and size of the watermark image

$marge_right = 10; 
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);

// Use 50% Transparency merges watermarks and images

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 memory

imagepng($im, 'photo_stamp.png');
imagedestroy($im); 
?>

This article explains how to create a semi-transparent watermark in PHP using the imagecopymerge() function. For more information, please Follow php Chinese website.

Related recommendations:

Discuz! Tutorial: How to modify the theme views through a simple php file?

php method of obtaining time

php object-oriented selection sorting example explanation

The above is the detailed content of PHP uses the imagecopymerge() function to create a semi-transparent watermark method. 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