Home >Backend Development >PHP Problem >What to do if the Chinese text watermark in php is garbled

What to do if the Chinese text watermark in php is garbled

藏色散人
藏色散人Original
2022-11-24 09:40:191858browse

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".

What to do if the Chinese text watermark in php is garbled

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.

1. Positioning problem

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

2. Solution ideas

  • First find the corresponding font on the Windows system. We find the corresponding font through the following directory: C:\Windows\Fonts
    What to do if the Chinese text watermark in php is garbled
    Search under this folder: Microsoft Yahei keywords, the following results appear :
    What to do if the Chinese text watermark in php is garbled

  • 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
    What to do if the Chinese text watermark in php is garbled
    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
  • Refresh font cache
fc-cache
  • View installed fonts
fc-list

What to do if the Chinese text watermark in php is garbled 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!

Statement:
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