使用imagecopymerge() 函數(shù)創(chuàng)建半透明水印,供大家參考,具體內(nèi)容如下
?php // 加載要加水印的圖像 $im = imagecreatefromjpeg('photo.jpeg'); // 首先我們從 GD 手動創(chuàng)建水印圖像 $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); // 設(shè)置水印圖像的位置和大小 $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); // 將圖像保存到文件,并釋放內(nèi)存 imagepng($im, 'photo_stamp.png'); imagedestroy($im); ?>
半透明水印:
本示例使用 imagecopymerge() 函數(shù) 來合并水印圖像和原始圖像。 我們可以控制水印的透明度,在本例中是 50% 的透明度。 在實際使用中, 使用半透明水印可以在不影響用戶觀看圖像的前提下進行版權(quán)保護。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。