如何在imagestring()中加载自定义字体


How Can I Load My Custom Font in imagestring()?

我的问题是Q标题。

我试过了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

编辑:我的字体。

引用我自己的话,您应该使用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);