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);
}
任何幫助將不勝感激, 尼古拉斯。