0
我需要創建一個水印將其應用於圖片並將其另存爲一個不同的名稱。目前的腳本工作得很好,但唯一的問題是我需要增加「示例文本」的大小並將背景從黑色變爲白色。我嘗試了不同的場景,改變了不透明度,但仍然無法更改背景顏色。php,gd,創建水印,更改水印文本大小和背景顏色,imagecreatefromjpeg
function watermark($imag_path, $photo_id) {
// Load the stamp and the photo to apply the watermark to
$im = imagecreatefromjpeg("$imag_path");
echo "imag_path is $imag_path and photoid is $photo_id";
// First we create our stamp image manually from GD
$stamp = imagecreatetruecolor(490, 20);
//$im = imagecreatefromjpeg("$photo_id");
imagestring($stamp, 5, 20, 2, 'sample text', 0xff0000);
// 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 (transparency) of 100%
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 100);
$new_photo_id = $photo_id . "sample.JPG";
// Save the image to file and free memory
imagejpeg($im, "tmp/$new_photo_id");
imagedestroy($im);
}
我需要將帶水印的圖片保存在磁盤上,以便稍後在網站上上傳。 – Michael 2010-09-15 19:40:34
所以只需刪除第二行並更改最後一行(用您的文件名替換'null') – Alnitak 2010-09-15 19:47:01
非常感謝,您讓我的一天! – Michael 2010-09-15 20:09:42