Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取PHP的imagefttext()以显示中文字符_Php_Image_Character Encoding - Fatal编程技术网

获取PHP的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

我试图让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 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'


使其正常工作

[请在字体文件夹中下载字体并重试,因为我已经在本地服务器上完成了此文本]