【发布时间】:2014-05-17 04:44:10
【问题描述】:
我在绘制 'Miscellaneous Symbols And Pictographs' 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);
//🌀 is the unicode html entity for a cyclone. It is under 'Miscellaneous Symbols And Pictographs'.
$text = "🌀 is a cyclone!";
imagettftext($im, 20, 0, 5, 22, $black, $font, $text);
//⛄ is the unicode html entity for a snowman. It is under 'Miscellaneous Symbols'.
$text = "⛄ is a snowman!";
imagettftext($im, 20, 0, 5, 52, $black, $font, $text);
imagepng($im);
imagedestroy($im);
?>
这是输出:
它应该是这样的:
如您所见,这些表情符号都位于不同的 Unicode 块下。旋风位于“杂项符号和象形文字”下方,绘制的是 HTML 实体而不是实际字符,但雪人位于“杂项符号”下方且绘制正确。我已经仔细检查以确保我使用的字体包含这两个字符。
明确地说,我希望绘制实际字符而不是 HTML 实体。
呈现为 UTF8 的相同字符:
【问题讨论】:
-
你能说清楚点吗?你希望输出是什么样的?
-
我认为我说得很清楚,但我会尝试改写它。我想要的是绘制实际字符而不是 html 实体。
-
显然
imagettftext的奇怪且毫无意义的 HTML 字符引用解析器不支持基本多语言平面之外的字符。如果您直接写入字符("???? is a cyclone!"并将文件另存为 UTF-8)或 UTF-8 字节转义"\xF0\x9F\x8C\x80 is a cyclone!",会发生什么情况? (可能仍然无法工作,但应该更接近......) -
当我执行其中任何一个建议时,输出如下:i.imgur.com/NjJfOnA.png 我假设绘制的 4 个字符与字符的字节有某种关联。
-
我认为它不会起作用。 GD 目前无法识别 UCS-4 CMAP。它将回退到使用 UCS-2 CMAP。无法访问 BMP 之外的字符。
标签: php unicode gd imagettftext