获取PHP的imagefttext()以显示中文字符
我试图让imagefttext显示中文字符,但它只显示方形框 下面是一些简化的代码来说明这个问题获取PHP的imagefttext()以显示中文字符,php,image,character-encoding,Php,Image,Character Encoding,我试图让imagefttext显示中文字符,但它只显示方形框 下面是一些简化的代码来说明这个问题 <?php // Create a 300x100 image $im = imagecreatetruecolor(300, 100); $red = imagecolorallocate($im, 0xFF, 0x00, 0x00); $black = imagecolorallocate($im, 0x00, 0x00, 0x00); // Make the background re
<?php
// Create a 300x100 image
$im = imagecreatetruecolor(300, 100);
$red = imagecolorallocate($im, 0xFF, 0x00, 0x00);
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);
// Make the background red
imagefilledrectangle($im, 0, 0, 299, 99, $red);
// Path to our ttf font file
$font_file = 'C:\\Windows\\Fonts\\arial.ttf';
// Draw the text '牧師' using font size 13
imagefttext($im, 13, 0, 105, 55, $black, $font_file, '牧師');
// Output image to the browser
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
这就是它产生的结果:
这与PHP中的字体或其他字符集设置有关吗
我试过各种字体,但我就是找不到合适的字体
牧師
要显示的字符我已设法使用SimSun字体让它们显示出来 替换 $font_file='C:\\Windows\\Fonts\\arial.ttf' 与 $font_file='C:\\Windows\\Fonts\\simsun.ttc'
使其正常工作[请在字体文件夹中下载字体并重试,因为我已经在本地服务器上完成了此文本]