2024 年日本 PHP 研討會

使用 imagecopymerge() 建立半透明浮水印

範例 #1 使用 imagecopymerge() 建立半透明浮水印

<?php
// Load the stamp and the photo to apply the watermark to
$im = imagecreatefromjpeg('photo.jpeg');

// First we create our stamp image manually 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 margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);

// Merge the stamp onto our photo with an opacity of 50%
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);

// Save the image to file and free memory
imagepng($im, 'photo_stamp.png');
imagedestroy($im);

?>
Using imagecopymerge() to create a translucent watermark
此範例使用 imagecopymerge() 將印記與原始影像合併。使用此函式,我們可以設定印記的不透明度 - 在我們的範例中,我們將其設定為 50% 不透明度。在實務上,這在版權保護方面很有用,因為半透明浮水印難以移除,同時又能讓觀看者看到影像。

新增註釋

使用者貢獻的註釋

此頁面尚無使用者貢獻的註釋。
To Top