Home>Article>Backend Development> Solution to the problem of garbled watermark generated by GD library
The GD library can be used to process image watermarks. In some circumstances, someone may find that the watermark text generated by GD is garbled. This article will share how to solve the problem of garbled watermarks generated by the GD library.
Recently, a project underwent server migration. After deployment, it was discovered that one of the functions of adding watermark text to pictures had garbled characters. It was confirmed that there was no problem with the function code. At the same time, the project codes were all encoded in UTF-8. There is no encoding problem, and the possibility of problems with the font file has also been checked and ruled out. After finally consulting the information, a PHP compilation parameter was locked --enable-gd-jis-conv.
--enable-gd-jis-conv:
If it is enabled when compiling PHP – If the enable-gd-jis-conv option is used, non-ASCII characters (such as Chinese characters, pinyin, Greek and arrows) will be treated as EUC-JP encoding, eventually causing normal Chinese to become garbled
Solution:
1. Remove the --enable-gd-jis-conv option and recompile php
2. Convert characters to html entities
mb_convert_encoding ('测试', 'HTML-ENTITIES', 'UTF-8');
Related recommendations:
Detailed tutorial on how to use the GD library to complete the verification code effect in PHP
What is the GD library? Detailed introduction to loading GD library in PHP
php Summary of several functions of GD library to generate images
php image processing image background, canvas operation
php image processing use imagecopy function to add image watermark example
The above is the detailed content of Solution to the problem of garbled watermark generated by GD library. For more information, please follow other related articles on the PHP Chinese website!