php imagettftext和特定的表情符号
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php imagettftext和特定的表情符号,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2406字,纯文字阅读大概需要4分钟。
内容图文
![php imagettftext和特定的表情符号](/upload/InfoBanner/zyjiaocheng/703/ccb49843ff144c4d94b7ad5e2f6f0230.jpg)
我遇到了一个问题,绘制了“杂项符号和象形文字”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的相同字符:
解决方法:
我遇到了与阿比盖尔TTF同样的问题.经过一些研究,我找到了这个链接
https://bugs.php.net/bug.php?id=17955
其中有这个示例脚本:
<?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有时会放入正方形,有时它会使角色留空.我真的更喜欢永远给出空白字符,因为它返回WIDTH = 0和HEIGHT = 0而广场可以返回有很多不同的大小.如果GD标准化总是给出一个没有大小的空白字符,那么你所要做的就是寻找它.否则 – 你必须通过箍来找出一个正方形被退回.
我希望这有帮助!
内容总结
以上是互联网集市为您收集整理的php imagettftext和特定的表情符号全部内容,希望文章能够帮你解决php imagettftext和特定的表情符号所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。