Pay attention to the default character encoding for the GD function imagettftext () in PHP.

Source: Internet
Author: User
Tags imagecopy
The GD function imagettftext () of PHP should pay attention to the default character encoding. Read the GD function imagettftext () of PHP and pay attention to the default character encoding. a small function is developed for a while, it is something similar to the personalized signature of the Forum. based on the member information, an image is automatically generated with text on it. Image merging uses imagecopy () and imagecopyresampled () "> <L a small function is being developed over the past, which is something similar to the personalized signature of the Forum, automatically generates an image containing text based on the member information. You can use functions such as imagecopy () and imagecopyresampled () to splice images. This makes it difficult to draw text. The text template is saved in a text file. The program first reads the file, replaces the variables with the data, and then uses the imagettftext () function to draw the image, unfortunately, the picture is garbled @_@...... So Google search related issues, found that most people are saying that the imagettftext () function passed the string to UTF-8 encoding, and PHP official manual also clearly says "UTF-8 encoding string can be directly transferred", but the problem is that the template file encoding is originally UTF-8, this is a bit inexplicable. In desperation, I used EmEditor to open the original template file and try to convert it into different codes and compare it with the garbled code output by GD, the results showed that the conversion to the EUC-JP encoding and GD output garbled ...... That is to say, the default GD encoding on the server here is the EUC-JP, which is a Japanese encoding. I found that no related options were found in the settings of php. ini. so another problem arises. where is the default encoding set? He was also the eldest brother of Shi wenniu and found that the "-enable-gd-jis-conv" parameter in the PHP compilation parameter was very suspicious, google found a lot of garbled issues related to this compilation parameter ...... The official parameter description is "GD: Enable JIS-mapped Japanese font support. ", that is, to allow GD to support the Japanese-encoded font (which is hateful, why does it not support the compilation option of the Chinese-encoded font ...... PHP also has nationality discrimination = B). If this option is enabled, GD will make the TTF font larger than 127 (that is, it is not part of the standard Latin font) ing based on the Japanese JIS sequence will naturally become garbled when used to map Chinese fonts. Remove this option to recompile and solve the problem. After this option is removed, the default imagettftext () encoding is changed to UTF-8, so that Chinese characters can be displayed normally ~

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.