日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php 表情选择,php imagettftext和特定的表情符号

發布時間:2025/3/12 php 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php 表情选择,php imagettftext和特定的表情符号 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我遇到了一個問題,繪制了“雜項符號和象形文字”unicode塊下的表情符號.

這是一個示例代碼:

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同樣的問題.經過一些研究,我找到了這個鏈接

其中有這個示例腳本:

$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,unicode,gd,imagettftext

來源: https://codeday.me/bug/20191003/1848431.html

總結

以上是生活随笔為你收集整理的php 表情选择,php imagettftext和特定的表情符号的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。