php function Imagefttext ()--enable-gd-jis-conv caused by Chinese garbled solution

Source: Internet
Author: User
Tags phpinfo

elaborated

in recent days with the company's PHP developers to test upcoming WEB site (to unforgettable youth years: http://hd.gfan.com ), there is no problem in the intranet test environment, but on-line testing when found through PHP of the GD function Imagefttext () References FreeType when the font writes text information to the image, the Chinese characters are garbled; For this problem, we have summed up three reasons that can cause Chinese garbled in the whole process of troubleshooting, as follows:

1,Linuxdoes the system character set support Chinese?


[Email protected]:~ #localeLANG =en_us. Utf-8language=en_us. Utf-8lc_ctype= "en_US. UTF-8 "[Email protected]:~ #echo $LANGen _us. UTF-8


## Tips

In the system, the character set that supports Chinese has unicode , gb1232 , utf-8 , GBK , gb18030 locale echo $LANG

Extended reading:

http://zh.wikipedia.org/wiki/GB18030

http://zh.wikipedia.org/wiki/GB2312

Http://zh.wikipedia.org/wiki/UTF8

Http://zh.wikipedia.org/wiki/GBK

Http://zh.wikipedia.org/wiki/Unicode

2,Linuxis supportedWindowsfont (bold, arial)?

before the test, the entireWEBsite'sPHPcode is passedSVNupdate to a server on the line, one thing to note is that when using thePHPof theGDfunctionImagefttext() When writing text to a picture, reference theWindows-side Font library (Simhei.ttfBlackbody,SIMSUN.TTCSong body,Simfang.ttfimitation), so we doubt whether becauseLinuxsystem does not supportWindowssystem font, which is caused by theLinuxThe system adds aWindowsSystem Font Library, unfortunately the problem is not resolved;LinuxThe same is true for font libraries;

## Extended reading:

How to Linux Add Windows Font

Http://www.cnblogs.com/hiflex/archive/2012/08/12/2634532.htmlhttp://os.51cto.com/art/201402/429516.htm

3, whether byPhpcompile parameter throws Chinese garbled problem?

through Phpinfo () function outputs the test environment and the online environment PHP compile parameters, compare with each other to find that the online environment is a lot more than the test environment. --enable-gd-jis-conv parameters, for which we are in PHP The following information is found in the official documentation:

*AlthoughImagettftext ()Document LabelMing only AcceptUTF-8encoded, but ifPHPcompile-time enabled–enable-gd-jis-convoption, then the non-ASCIIcharacter(such as kanji, pinyin, Greek, and arrowsHead) will be treated asEUC-JPCoding(Phpinfothe Chinese and American names"SupportJISencoded Fonts"),thus causing garbled characters(since Western fonts do not have kana or kanji characters, they are generally shown as all squares).

Although Imagettftext () documentation indicates it only accepts UTF-8 encoding, but If–enable-gd-jis-conv was specified when Compiling PHP, then non-ascii characters (like Chinese, accented characters, Greek and arrows) would be (mis-) treated Aseuc -JP encoding (referred to as ' jis-mapped Japanese Font support ' in phpinfo) leading to mojibake (this usually shows up as H Ollow rectangles, as most fontsfor Western text lacks glyphs for kanji or kana).

3,1enabledPhpParameters–enable-gd-jis-conv, the test results are as follows:

Firefox Browser Attach Web Debugging Tools Firebug

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/2F/41/wKioL1OevHWjgDyfAAI6xuoGo04679.jpg "title=" 3.png " alt= "Wkiol1oevhwjgdyfaai6xuogo04679.jpg"/>

# Tips : The result of the output, we can know that the server side is supported by the Chinese character set, the problem occurs in GD function Imagefttext () When the text information is written to the picture, there is a garbled situation, the additional test picture is as follows:


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/2F/41/wKiom1OevL-A4jJoAAIQqSD_d-U915.jpg "title=" 4.png " alt= "Wkiom1oevl-a4jjoaaiqqsd_d-u915.jpg"/>


3,2DisabledPhpParameters–enable-gd-jis-conv, the test results are as follows:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/2F/41/wKiom1OevN7ACrj2AAH5DC2PIOQ158.jpg "title=" 5.png " alt= "Wkiom1oevn7acrj2aah5dc2pioq158.jpg"/>


I want to say, debugging bug is a very careful, pay attention to teamwork, first of all, we first regardless of the problem is not caused by developers, operators, but you need to understand that the two departments it is a team, each other need to work together to solve the problem in the shortest possible time , because before we get the final conclusion, we are not sure who caused the problem, who should be responsible for it, hope this document can help everyone;

Extended reading:

Http://nekotoba.nfshost.com/b/2011/04/267/a-workaround-for-imagettftext-garbage-chracters-due-to-enable-gd-jis-conv


This article is from the "Step by foot, from Ops to DBA" blog, be sure to keep this source http://cfwlxf.blog.51cto.com/3966339/1427020

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.