基本上我正在尋找一種在GIF上寫動態文本的方法[最好通過PHP GD。]但我似乎無法讓這兩個函數發揮出色。可能使用PHP GD的imagecreatefromgif()和imagettftext()在一起?
參考:imagecreatefromgif & imagettftext
function load_gif($imgname)
{
$im = @imagecreatefromgif($imgname);
if(!$im)
{
$im = imagecreatetruecolor(150,30);
$bgc = imagecolorallocate($im,255,255,255);
$tc = imagecolorallocate($im,0,0,0);
imagefilledrectangle($im,0,0,150,30,$bgc);
imagestring($im,1,5,5,'Error loading ' . $imgname,$tc);
}
return $im;
}
if ($_GET['color'] == 'red')
{
header('Content-Type:image/gif');
//$img = imagecreatetruecolor(51,32); // THIS IS NEEDED FOR TEXT TO SHOW
$img = load_gif('map-bubble-' . $_GET['color'] . '.gif');
$black = imagecolorallocate($img,0,0,0);
$white = imagecolorallocate($img,255,255,255);
imagefilledrectangle($img,0,0,51,32,$black);
imagettftext($img,14,0,0,0,$white,'../arial.ttf','test');
imagegif($img);
imagedestroy($img);
}
讓我們看看你的代碼。告訴我們您收到的錯誤消息。 –
你是什麼意思,「我似乎無法讓這兩個功能玩得好」? – Residuum
如果你看看我剛剛添加的代碼示例,當我使用imagecreatetruecolor()定義$ img時,我可以使用文本,但它是純色的背景色,但是如果不使用文本,則使用imagecreatefromgif()。這意味着它是一個或另一個,因此不玩很好 –