更新:測試後TTF文件似乎在那裏。 更新:更改爲字體文件的相對路徑。仍然不起作用。PHP GD給出錯誤
當我嘗試使用GD通過PHP製作圖像時,出現以下錯誤。
[週二01九月19時44分15秒2009] [錯誤] [客戶端IP 地址] PHP的警告: imagettftext()[function.imagettftext]: 找不到/打開字體在 /www/vhosts/website.com/htdocs/trial/TextToImage.class.php 上線38
我改變了路徑,因爲它是給我同樣的錯誤的字體。我通過將文件放入文件夾來將字體添加到服務器。我錯過了什麼?
/**
* @name : makeImageF
*
* Function for create image from text with selected font.
*
* @param String $text : String to convert into the Image.
* @param String $font : Font name of the text.
* @param int $W : Width of the Image.
* @param int $H : Hight of the Image.
* @param int $X : x-coordinate of the text into the image.
* @param int $Y : y-coordinate of the text into the image.
* @param int $fsize : Font size of text.
* @param array $color : RGB color array for text color.
* @param array $bgcolor : RGB color array for background.
*
*/
public function makeImageF($text, $font="/www/vhosts/website.com/htdocs/trial/CENTURY.TTF", $W=200, $H=20, $X=0, $Y=0, $fsize=18, $color=array(0x0,0x0,0x0), $bgcolor=array(0xFF,0xFF,0xFF)){
$this->im = @imagecreate($W, $H)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($this->im, $bgcolor[0], $bgcolor[1], $bgcolor[2]); //RGB color background.
$text_color = imagecolorallocate($this->im, $color[0], $color[1], $color[2]); //RGB color text.
imagettftext($this->im, $fsize, $X, $Y, $fsize, $text_color, $font, $text);
}
你試過把字體與類/索引文件,並通過相對路徑使用它,只是爲了調試? – 2009-09-01 20:36:19