Home > Backend Development > PHP Tutorial > Solution to the problem of garbled watermark generated by GD library

Solution to the problem of garbled watermark generated by GD library

*文
Release: 2023-03-18 09:10:02
Original
2592 people have browsed it

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:
Copy after login

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');
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template