2011-11-10 27 views
4

當使用imagettftext和通過imagecolortransparent渲染透明的圖像時,文本的邊框似乎已經與原始背景顏色(黑色)混合而不是透明,從而創建如下所示的文本輪廓:
http://i.stack.imgur.com/xLSkK.png 0123反對使用和imagestring,在這裏:
http://i.imgur.com/5R0gT.png
是否可以通過imagettftext和imagecolortransparent獲得真正的透明度?

現在我不知道是否有更好的方法來合成圖像,以便他們從一開始就建立透明的,或者有一些其他的透明度方法我不意識到。下面是我使用的相關PHP代碼:

if ($type) { 
    $icon = imagecreatefrompng("images/" . $type . ".png"); 
} 
else { 
    die('Invalid type. Valid types are: arcane, elysian, divine, spectral'); 
} 
$img = imagecreatetruecolor(128, 25); 
$black = imagecolorallocate($img, 0, 0, 0); 
imagecolortransparent($img, $black); 
imagecopymerge($img,$icon,0,0,0,0,28,25,100); 

imagettftext($img, 16, 0, 30, 20, $col, $font, $input_num); 

header("Content-type: image/png"); 
imagepng($img); 

回答

1

imagecolortransparent絕不會因爲抗鋸齒的工作非常好---近輪廓的背景顏色不是真正的黑色。您最好的選擇將是首先使用帶有透明區域的PNG圖像,而不是黑色背景的圖像。

相關問題