2012-07-10 55 views
1

我正在嘗試使用imagettftext來創建一個使用希臘文字「απότον/την」的圖像。PHP - 使用希臘文字創建imagettftext圖像

該文本是從MySQL數據庫表中讀取的,該表中的排序規則設置爲utf8-unicode-ci。

將文本從數據庫中取出爲「我希望我的」「我的/我的」「我的」。

這裏的(從php.net擡起)

header('Content-Type: image/png'); 
// Create the image 
$im = imagecreatetruecolor(400, 30); 

// Create some colors 
$white = imagecolorallocate($im, 255, 255, 255); 
$grey = imagecolorallocate($im, 128, 128, 128); 
$black = imagecolorallocate($im, 0, 0, 0); 
imagefilledrectangle($im, 0, 0, 399, 29, $white); 

// The text to draw 
$text = html_entity_decode('από τον/την', ENT_COMPAT, 'UTF-8'); 

// Replace path by your own font path 
$font = '/Applications/MAMP/htdocs/test.localhost/libs/fonts/CustomFont.ttf'; 

// Add some shadow to the text 
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text); 

// Add the text 
imagettftext($im, 20, 0, 10, 20, $black, $font, $text); 

// Using imagepng() results in clearer text compared with imagejpeg() 
imagepng($im); 
imagedestroy($im); 

這產生了「αI€IOE I「的圖像ον/ I「I·Î½" 的代碼,而不是「απότον/ την」。

任何想法?

非常感謝。

+0

你有沒有直接從數據庫中嘗試過嗎? – 2012-07-10 15:21:40

+0

是的,從數據庫讀取時,它出現爲這個字符串「我希望我的」我的/我的「我的」,這就是我插入html_entity_decode – Shmoyko 2012-07-10 15:34:41

+0

我的意思是沒有打印出來,瀏覽器/ os的有時可能會搞砸編碼。 – 2012-07-11 12:09:54

回答

1

使用其他字體一樣

$font = 'arial.ttf'; 

和它工作得很好