2012-04-19 75 views
0

我有腳本爲圖像(JPG)添加水印(PNG,透明)。在捕捉時可以很好地工作 - 在某些方面,水印會改變顏色並使其不透明。 這是我的代碼使用加水痕:PHP創建的水印看起來很奇怪

$im = imagecreatefromjpeg('../../pics/'.$ran.'_large.jpg'); 
$stamp = imagecreatefrompng('a.png'); 

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

imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 70); 

// Save the image to file and free memory 
imagejpeg($im, '../../pics/'.$ran.'_large.jpg'); 
imagedestroy($im); 

Image with watermark after PHP generates it (wrong way)

回答

0

感謝您的幫助球員 - I found answer in this site

$im = imagecreatefromjpeg('../../pics/'.$ran.'_large.jpg'); 
$stamp = imagecreatefrompng('a.png'); 

imagealphablending($im, true); 

$marge_right = 10; 
$marge_bottom = 10; 

$sx = imagesx($stamp); 
$sy = imagesy($stamp); 

$offset = 10; 

imagecopy($im, $stamp, imagesx($im) - imagesx($stamp) - $offset, imagesy($im) - imagesy($stamp) - $offset, 0, 0, imagesx($stamp), imagesy($stamp)); 
// Save the image to file and free memory 
imagejpeg($im, '../../pics/'.$ran.'_large.jpg'); 
imagedestroy($im); 
0

從PNG創建後,當談到與α映射PNG圖像不要忘了這些功能:

imagealphablending($stamp,false); 
imagesavealpha($stamp,true); 

看看它有什麼區別?

1

您的輸出圖像格式爲jpeg。 Jpeg不支持交易。將輸出格式更改爲png。

還建議您使用圖像魔術。 Gd是非常原始的。

相關問題