2011-07-30 31 views
1

我已經安裝了--enable-gd-jis-conv = shared和--enable-mbstring = shared,但我仍然無法使用字體文件將日文文本保存到圖像中。用日文文本保存圖像

如果將「英雄時代」更改爲英文文本,圖片可以用日文字體的英文字符正確創建,但日文文本可能會出現奇怪的正方形和其他內容。

public function makeJapaneseCharacter($font="static/JFONT.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, mb_convert_encoding('英雄時代', 'SJIS', 'UTF-8')); 
$this->saveAsPng("jchar", "static/"); 
} 


public function saveAsPng($fileName, $location= null) 
{   

    $_fileName = $fileName.".png"; 
    $_fileName = is_null($location)?$_fileName:$location.$_fileName; 
    return imagepng($this->im, $_fileName);   
}  

任何幫助將不勝感激, 尼古拉斯。

回答

0

嘗試寫L'英雄時代'而不是'英雄時代'。我不知道你用的是什麼語言,但是這就是你必須在C.

0
imagettftext($this->im, 58, 0, 50, 100, 
    $text_color, $font, 
    mb_convert_encoding('佳人', 'UTF8', 'UTF-8')); 

做的鑰匙已經發現了什麼。