phpµÄimagettftext º¯Êý³öÏÖÂÒÂëµÄ½â¾ö·½·¨
phpµÄimagettftext º¯Êý³öÏÖÂÒÂëµÄ½â¾ö·½·¨£º½ñÌìÓöµ½Ò»¸öÎÊÌ⣬¾ÍÊÇÍùͼƬÉÏ´òÎÄ×Öˮӡ£¬µ±ÊǺº×ÖµÄʱºò³öÏÖÁËÂÒÂ룬ÊÇÓ¢ÎÄʱºò²¢Ã»ÓгöÏÖÂÒÂë¡£
²é×ÊÁϺó×îÖÕÕÒµ½Á½ÖÖ½â¾ö·½°¸£¬·Ö±ðÈçÏ£º
1¡¢±àÒëphp¼¶£¬ÖØбàÒëgd¿âÀ©Õ¹
¾ÍÊÇÔÚ±àÒëµÄʱºò¶àÁËÕâ¸öÑ¡Ïî¡£
--enable-gd-jis-conv
È¥µôÒÔºó¾Í¿ÉÒÔÁË£¬ºÃÏñÊǸöbug£¬²»¹ý»¹ºÃÔÝʱ½â¾öÁË¡£Ò²ÄÜÓÃÁË¡£
ÌùÉϹٷ½µÄ½âÊÍ£º
There is no fallback ot UTF-8. It accepts UTF-8 by default. The problem
about JIS is when you pass a non UTF-8 string, it can be seen as JIS
enconded string.
About the mbstring issues, I have no idea how it works and how it
affects the input parameters. It is something happening before we got
the hand in the gd function.
Please try using:
- Without mbstring, with jis enabled
- Without mbstring, without jis
2¡¢php´úÂ뼶£¬¼´Í¨¹ýת»»Îªunicode±àÂë½â¾ö´ËÎÊÌâ
ÔÀí£º
ËäÈ» imagettftext() Îĵµ±ê Ã÷Ö»½ÓÊÜUTF-8±àÂ룬µ«Èç¹ûPHP±àÒëʱÆôÓèCenable-gd-jis-convÑ¡ÏîµÄ»°£¬ÄÇô·ÇASCII×Ö·û(ÀýÈ纺×Ö¡¢Æ´Òô¡¢Ï£À°Îĺͼý Í·) »á±»µ±³ÉEUC-JP±àÂë (phpinfoÖÐÃÀÆäÃûÔ»¡°Ö§³ÖJIS±àÂëµÄ×ÖÌ塱), ´Ó¶øµ¼ÖÂÂÒÂë(ÓÉÓÚÎ÷ÎÄ×ÖÌåûÓмÙÃû»òºº×Ö£¬Ò»°ã±íÏÖΪȫ²¿ÊÇ·½¿ò)¡£
Although imagettftext() documentation indicates it only accepts UTF-8 encoding, but if ¨Cenable-gd-jis-conv is specified when compiling PHP, then non-ASCII characters (like Chinese, accented characters, Greek and arrows) will be (mis-)treated as EUC-JP encoding (referred to as ¡°JIS-mapped Japanese Font Support¡± in phpinfo) leading to mojibake (this usually shows up as hollow rectangles, as most fonts for western text lacks glyphs for kanji or kana).
ÍøÉϴ󲿷ֶԴ˵Ľâ¾ö·½·¨ÊÇÖØбàÒëPHP£¬µ«ÊÇÕâÖ»ÓÐ×Ô¼º¼ÜÉè·þÎñÆ÷µÄʱºò²ÅÓÐÓ᣶ÔÓÚ¸¶·Ñ ¿Õ¼ä (ÌرðÊÇÿ¸öÔ²»µ½1ÃÀÔªµÄ¸¶·Ñ¿Õ¼ä) ¾ÍûÕÞÁË¡£²»¹ýimagettftext()Ò²½ÓÊÜÁíÍâÒ»ÖÖ×Ö·û±íʾ·½·¨£¬ÀàËÆHTMLµÄ×Ö·û²Î¿¼¡£Ëµ¡°ÀàËÆ¡±ÊÇÒòΪGDÖ»½ÓÊÜÊý×ֲο¼£¬ËùÒÔÄÚ²¿º¯Êý (Èç mb_convert_encoding) ת³öÀ´µÄûÓᣠÒÔϵĺ¯Êý¿ÉÒÔ½«UTF-8ת»»³É×Ö·û²Î¿¼:
A popular response online is to recompile PHP, but that only works if you¡¯re running your own server. For paid hosting (especially paid hosting that costs less than a dollar a month) this method is kinda stumped. But imagettftext() also accepts another way for representing characters, similar to HTML¡¯s character references. ¡°Similar¡± because it only accepts numeric references, so named references converted by internal functions (like mb_convert_encoding) is of no use. The function below converts UTF-8 into character references:
$str = gb2utf8($str); //ÏÈ°Ñ×Ö·û´®×ª»»³Éutf8£¬È»ºóÓú¯ÊýÔÙ´Îת»» ImageTTFText($ims[$char_num-1], $fontsize, 0, 0, 20, $font_color, $fnt, to_entities($str)); function to_entities($string){ $len = strlen($string); $buf = ""; for($i = 0; $i < $len; $i++){ if (ord($string[$i]) <= 127){ $buf .= $string[$i]; } else if (ord ($string[$i]) <192){ //unexpected 2nd, 3rd or 4th byte $buf .= "�"; } else if (ord ($string[$i]) <224){ //first byte of 2-byte seq $buf .= sprintf("&#%d;", ((ord($string[$i + 0]) & 31) << 6) + (ord($string[$i + 1]) & 63) ); $i += 1; } else if (ord ($string[$i]) <240){ //first byte of 3-byte seq $buf .= sprintf("&#%d;", ((ord($string[$i + 0]) & 15) << 12) + ((ord($string[$i + 1]) & 63) << 6) + (ord($string[$i + 2]) & 63) ); $i += 2; } else { //first byte of 4-byte seq $buf .= sprintf("&#%d;", ((ord($string[$i + 0]) & 7) << 18) + ((ord($string[$i + 1]) & 63) << 12) + ((ord($string[$i + 2]) & 63) << 6) + (ord($string[$i + 3]) & 63) ); $i += 3; } } return $buf; }
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ