我試圖在白色圖像中放置一個徽標,並使其成爲半透明以用作水印。PHP - 創建一個帶有半透明徽標/水印的PNG文件
這裏是我的代碼...
// load the stamp and the photo to apply the watermark to
if (file_exists($logoPath)) {
$im = imagecreatefrompng($logoPath);
$size = getimagesize($logoPath);
$stamp = imagecreatetruecolor(612, 792);
imagefilledrectangle($stamp, 0, 0, 612-1, 792-1, 0xFFFFFF);
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// center width and height
$centerX=$sx/2-$size[0]/2;
$centerY=$sy/2-$size[1]/2;
$res=imagecopymerge($stamp, $im, $centerX,$centerY, 0, 0, $sx, $sy, 15);
$waterPath = $watermark_path.$broker_id."_watermark.png";
// Save the image to file and free memory
imagepng($stamp, $waterPath);
imagedestroy($stamp);
imagedestroy($im);
}
這一切對我來說很好,但是當我運行它,我得到這個...
http://i43.tinypic.com/2cyft06.jpg
...,你可以請參閱圖像的右下四角因某種原因變色。
我認爲你需要做一些字母。 – putvande
yeah..maybe ..但是logo * *正在被imagecopymerge正確透明化......它只是在$圖像上標出了所有「圖像之後」的東西......非常奇怪 – menriquez