Home>Article>Backend Development> What to do if the Chinese text watermark in php is garbled
Solution to Chinese garbled text watermark in php: 1. Find the corresponding font on the Windows system; 2. Upload the searched font file to the server; 3. Install the font through "yum -y install ttmkfdir" ;4. Refresh the font cache through "fc-cache".
Operating environment for this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.
php What should I do if the text watermark is garbled in Chinese?
Solve the problem of Chinese garbled image watermarks under Linux
In business scenarios, you need to upload images through the APP and add watermarks to the images. On the upper layer, because there are Chinese characters involved in the geographical location, garbled square characters will appear. The initial consideration is that the Chinese font is not supported on the server.
First of all, by analyzing the source code, we found that the font-style used in the method of adding watermarks defaults to Microsoft Yahei font. This Fonts generally only exist on Windows systems, so there is a reasonable explanation for the garbled characters on the server
First find the corresponding font on the Windows system. We find the corresponding font through the following directory: C:\Windows\Fonts
Search under this folder: Microsoft Yahei keywords, the following results appear :
Upload the searched font files to the server
First enter the following directory of the Linux server: /usr/share/fonts/
Create a chinese file
mkdir chinese
We will upload the font file we just found to this folder
We will see that three files will appear in this directory. Although they are not files named Microsoft Yahei, don't be afraid. In fact, these three files are the ontology of Microsoft Yahei.
Next we execute the following commands in order to make the Microsoft Yahei font take effect
Install the font
yum -y install ttmkfdir
fc-cache
fc-list
We can see the three Chinese font folders The font files have all taken effect.
After testing, the problem of garbled Chinese watermarks in pictures has been successfully solved.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What to do if the Chinese text watermark in php is garbled. For more information, please follow other related articles on the PHP Chinese website!