Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.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 imagettftext和特定表情符号_Php_Unicode_Gd_Imagettftext - Fatal编程技术网

php imagettftext和特定表情符号

php imagettftext和特定表情符号,php,unicode,gd,imagettftext,Php,Unicode,Gd,Imagettftext,我在“杂项符号和象形文字”unicode块下绘制表情符号时遇到问题 下面是一个示例代码: <?php header('Content-Type: image/png'); $im = imagecreatetruecolor(290, 60); $grey = imagecolorallocate($im, 200, 200, 200); $black = imagecolorallocate($im, 0, 0, 0); imagefilled

我在“杂项符号和象形文字”unicode块下绘制表情符号时遇到问题

下面是一个示例代码:

<?php
    header('Content-Type: image/png');

    $im = imagecreatetruecolor(290, 60);

    $grey = imagecolorallocate($im, 200, 200, 200);
    $black = imagecolorallocate($im, 0, 0, 0);
    imagefilledrectangle($im, 0, 0, 289, 59, $grey);

    $font = 'seguisym.ttf';
    $font = realpath($font);

    //&#127744; is the unicode html entity for a cyclone. It is under 'Miscellaneous Symbols And Pictographs'.
    $text = "&#127744; is a cyclone!";
    imagettftext($im, 20, 0, 5, 22, $black, $font, $text);

    //&#9924; is the unicode html entity for a snowman. It is under 'Miscellaneous Symbols'.
    $text = "&#9924; is a snowman!";
    imagettftext($im, 20, 0, 5, 52, $black, $font, $text);

    imagepng($im);
    imagedestroy($im);
?>

以下是输出:

下面是它的外观:

如您所见,这些表情符号都位于不同的Unicode块下。旋风在“杂项符号和象形文字”下,HTML实体被绘制,而不是实际字符,但雪人在“杂项符号”下,并且绘制正确。我已仔细检查以确保我使用的字体包含这两个字符

为了清楚起见,我希望绘制实际的字符,而不是HTML实体

呈现为UTF8的相同字符:


我在Abigail TTF中遇到了同样的问题。经过一些研究,我发现了这个联系

其中包含以下示例脚本:

<?php
$str = "this is a test";
$str = iconv("UCS-2", "UTF-8", preg_replace("/(.)/","\xf0\$1", $str));

$fsize = 32;
$ffile= "C:/wamp/www/gm/fonts/Aztec/101_Aztec SymbolZ.ttf";

$size = ImageTTFBBox($fsize, 0, $ffile, $str);

$txt_width = ($size[2] - $size[0]);
$txt_height = ($size[1] - $size[7]);

$im_width = $txt_width * 1.5;
$im_height = $txt_height * 1.5;

$im = ImageCreateTrueColor($im_width, $im_height);
$black = ImageColorAllocate($im, 0, 0, 0);
$white = ImageColorAllocate($im, 255, 255, 255);

$txt_x = ($im_width - $txt_width) / 2;
$txt_y = ($im_height - $txt_height) / 2 + $txt_height;

ImageFilledRectangle($im, 0, 0, $im_width, $im_height, $white);
imagecolortransparent( $im, $white );
ImageTTFText($im, $fsize, 0, $txt_x, $txt_y, $black, $ffile, $str);

Imagegif($im, "./test.gif");
ImageDestroy($im);
?>

他们的回答是:您必须正确地将字符串转换为Unicdoe。这使得Abigail字体正确显示。不幸的是,我仍在研究如何使非标准TTF文件正确显示。但我认为这只是一个问题,他们把实际的字体(如你的旋风图像)放在哪里

另一个令人沮丧的因素是GD有时会放入正方形,有时会将字符留空。我真的更喜欢空白字符总是给予,因为这回来了宽度= 0和高度= 0,而平方可以回来了很多不同的大小。如果GD总是返回一个没有大小的空白字符,那么您所要做的就是查找它。否则,你必须跳过铁环才能算出一个正方形被返回


我希望这有帮助!:-)

你能说清楚点吗?您希望输出是什么样子的?我想我已经说得很清楚了,但我会尝试重新表述。我想要的是绘制实际的字符,而不是html实体。显然,
imagettftext
奇怪而毫无意义的html字符引用解析器不支持基本多语言平面之外的字符。如果直接写入字符(
“当我执行上述任一建议时,这就是输出:我假设绘制的4个字符以某种方式与字符的字节相关。我认为这不会起作用。GD目前无法识别UCS-4 CMAP。它将退回到使用UCS-2 CMAP。无法访问BMP以外的字符。