国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

在GD中輸出漢字的函數

2024-09-04 11:47:58
字體:
來源:轉載
供稿:網友

感謝sadly為我們寫出了在GD中輸出漢字的函數,我在使用中發現此版本輸出的字符串必須為純中文,不能夾雜英文,隨修改了此bug,與大家分享。

  1. <? 
  2. //Program writen by sadly www.survivalescaperooms.com 
  3. //modified by agun 2013/6/20 
  4. function gb2utf8($gb
  5. if(!trim($gb)) 
  6. return $gb
  7. $filename="gb2312.txt"
  8. $tmp=file($filename); 
  9. $codetable=array(); 
  10. while(list($key,$value)=each($tmp)) 
  11. $codetable[hexdec(substr($value,0,6))]=substr($value,7,6); 
  12. $ret=""
  13. $utf8=""
  14. while($gb
  15. if (ord(substr($gb,0,1))>127) 
  16. $this=substr($gb,0,2); 
  17. $gb=substr($gb,2,strlen($gb)); 
  18. $utf8=u2utf8(hexdec($codetable[hexdec(bin2hex($this))-0x8080])); 
  19. for($i=0;$i<strlen($utf8);$i+=3) 
  20. $ret.=chr(substr($utf8,$i,3)); 
  21. else 
  22. $ret.=substr($gb,0,1); 
  23. $gb=substr($gb,1,strlen($gb)); 
  24. return $ret
  25. function u2utf8($c
  26. for($i=0;$i<count($c);$i++) 
  27. $str=""
  28. if ($c < 0x80) { 
  29. $str.=$c
  30. else if ($c < 0x800) { 
  31. $str.=(0xC0 | $c>>6); 
  32. $str.=(0x80 | $c & 0x3F); 
  33. else if ($c < 0x10000) { 
  34. $str.=(0xE0 | $c>>12); 
  35. $str.=(0x80 | $c>>6 & 0x3F); 
  36. $str.=(0x80 | $c & 0x3F); 
  37. else if ($c < 0x200000) { 
  38. $str.=(0xF0 | $c>>18); 
  39. $str.=(0x80 | $c>>12 & 0x3F); 
  40. $str.=(0x80 | $c>>6 & 0x3F); 
  41. $str.=(0x80 | $c & 0x3F); 
  42. return $str
  43. Header("Content-type: image/gif"); 
  44. $im = imagecreate(300,150); 
  45. $bkg = ImageColorAllocate($im, 0,0,0); 
  46. $clr = ImageColorAllocate($im, 255,255,255); 
  47. $fnt = "c:windowsfontssimsun.ttf"
  48. //include("gb2utf8.php"); 
  49. $str = gb2utf8("中國agun阿棍"); 
  50. ImageTTFText($im, 30, 0, 50,50, $clr$fnt$str); 
  51. ImageGif($im); 
  52. ImageDestroy($im); 
  53. ?> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 曲沃县| 浙江省| 延川县| 淮南市| 民丰县| 宁夏| 班戈县| 夏邑县| 灵川县| 望都县| 贵德县| 晋江市| 攀枝花市| 天长市| 博客| 贵定县| 邛崃市| 庆元县| 渭南市| 清河县| 承德县| 平潭县| 通州区| 云阳县| 荥阳市| 淮安市| 琼中| 文成县| 长顺县| 得荣县| 水富县| 福安市| 东丰县| 保康县| 漳州市| 四会市| 如东县| 秦皇岛市| 茌平县| 耒阳市| 连州市|