2014-10-08 28 views
1

我的問題是Q標題。如何在imagestring()中加載我的自定義字體?

我試過http://www.php.net/manual/en/function.imageloadfont.php和: imageloadfont();

,但我看不出有什麼變化,我得到錯誤:

Warning: imageloadfont(): gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully in E:\xampp\htdocs\test\texts\text01.php on line 3 

Warning: imageloadfont(): Error reading font, invalid font header in E:\xampp\htdocs\test\texts\text01.php on line 3 

編輯: My font

+0

只能負載TrueType字體使用GD。你能提供你的字體文件嗎?謝謝。 – 2014-10-08 12:56:49

+0

假設你的字體是TrueType(.ttf),你應該使用['imagettftext()'](http://php.net/manual/en/function.imagettftext.php),而不是'imagestring()'。如果你真的想使用'imagestring()',那麼你的自定義字體與['imageloadfont()'](http://php.net/manual/en/function.imageloadfont)中列出的字體文件格式規範不匹配.php)手冊頁。 – timclutton 2014-10-08 13:55:04

+0

看看我的編輯請 – Nastary 2014-10-08 14:37:59

回答

2

要引用myself,您應該使用imagettftext()而不是imagestring()

實施例的使用,簡寫/改編自手冊頁面:

$im = imagecreatetruecolor(400, 30); 

// Create some colors and set background to white. 
$white = imagecolorallocate($im, 255, 255, 255); 
$black = imagecolorallocate($im, 0, 0, 0); 
imagefilledrectangle($im, 0, 0, 399, 29, $white); 

// The text to draw 
$text = 'Testing...'; 
// Replace path by your own font path 
$font = 'btitr.ttf'; 

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

// Using imagepng() results in clearer text compared with imagejpeg() 
imagepng($im, 'path_to_file.png'); 
imagedestroy($im); 
+0

這給了我普通的白色背景.. – sujitrulz 2015-04-20 07:06:44

+0

@sujitrulz這可能意味着錯誤已經產生,但'display_errors'已關閉,所以你看不到它。檢查PHP錯誤日誌。 – timclutton 2015-04-20 07:14:10