Home Backend Development PHP Tutorial Solve the GD Chinese garbled problem_PHP tutorial

Solve the GD Chinese garbled problem_PHP tutorial

Jul 21, 2016 pm 03:56 PM
Down Chinese Garbled characters use Library technology of Related Research solve output question

今天仔细研究了下GD的一些相关技术,顺手也研究下GD中文乱码的问题。

  使用GD库输出中文字符串,调用imagestring是没有用的。需要使用imagettftext()函数。imagettftext函数的具体使用就参考手册啦。

  下面给个使用实例:

   

<span style="COLOR: #000000"><br>$pic=imagecreate(250,30);  <br>$black=imagecolorallocate($pic,0,0,0);  <br>$white=imagecolorallocate($pic,255,255,255);  <br>$font="C://WINDOWS//Fonts//simhei.ttf";  //这里的路进需要注意下,必须是字符的路径 <br>$str ='php'.iconv('gb2312','utf-8','面对对象')." www.phpobject.net";  <br>imagettftext($pic,10,0,10,20,$white,$font,$str); <br>      </span>


    前面我给出一个简单的GD水印实例,只举例说明了使用图片如何水印的,这里给出一个文字水印的简单代码。

 
<span style="COLOR: #000000"><br><span style="COLOR: #0000bb"><?php <BR>$pic</SPAN><SPAN style="COLOR: #007700">=</SPAN><SPAN style="COLOR: #0000bb">imagecreate</SPAN><SPAN style="COLOR: #007700">(</SPAN><SPAN style="COLOR: #0000bb">250</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">30</SPAN><SPAN style="COLOR: #007700">); <BR></SPAN><SPAN style="COLOR: #0000bb">$black</SPAN><SPAN style="COLOR: #007700">=</SPAN><SPAN style="COLOR: #0000bb">imagecolorallocate</SPAN><SPAN style="COLOR: #007700">(</SPAN><SPAN style="COLOR: #0000bb">$pic</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">0</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">0</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">0</SPAN><SPAN style="COLOR: #007700">); <BR></SPAN><SPAN style="COLOR: #0000bb">$white</SPAN><SPAN style="COLOR: #007700">=</SPAN><SPAN style="COLOR: #0000bb">imagecolorallocate</SPAN><SPAN style="COLOR: #007700">(</SPAN><SPAN style="COLOR: #0000bb">$pic</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">255</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">255</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">255</SPAN><SPAN style="COLOR: #007700">); <BR></SPAN><SPAN style="COLOR: #0000bb">$font</SPAN><SPAN style="COLOR: #007700">=</SPAN><SPAN style="COLOR: #dd0000">"C://WINDOWS//Fonts//simhei.ttf"</SPAN><SPAN style="COLOR: #007700">; <BR></SPAN><SPAN style="COLOR: #0000bb">$str </SPAN><SPAN style="COLOR: #007700">=</SPAN><SPAN style="COLOR: #dd0000">'php'</SPAN><SPAN style="COLOR: #007700">.</SPAN><SPAN style="COLOR: #0000bb">iconv</SPAN><SPAN style="COLOR: #007700">(</SPAN><SPAN style="COLOR: #dd0000">'gb2312'</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #dd0000">'utf-8'</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #dd0000">'面对对象'</SPAN><SPAN style="COLOR: #007700">).</SPAN><SPAN style="COLOR: #dd0000">" www.phpobject.net"</SPAN><SPAN style="COLOR: #007700">; <BR></SPAN><SPAN style="COLOR: #0000bb">imagettftext</SPAN><SPAN style="COLOR: #007700">(</SPAN><SPAN style="COLOR: #0000bb">$pic</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">10</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">0</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">10</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">20</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">$white</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">$font</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">$str</SPAN><SPAN style="COLOR: #007700">); <br><br></SPAN><SPAN style="COLOR: #0000bb">header</SPAN><SPAN style="COLOR: #007700">(</SPAN><SPAN style="COLOR: #dd0000">"Content-type: image/jpeg"</SPAN><SPAN style="COLOR: #007700">); <BR></SPAN><SPAN style="COLOR: #0000bb">$filename</SPAN><SPAN style="COLOR: #007700">=</SPAN><SPAN style="COLOR: #dd0000">'../src/images/photo.jpg'</SPAN><SPAN style="COLOR: #007700">; <BR></SPAN><SPAN style="COLOR: #0000bb">$im</SPAN><SPAN style="COLOR: #007700">=</SPAN><SPAN style="COLOR: #0000bb">imagecreatefromjpeg</SPAN><SPAN style="COLOR: #007700">(</SPAN><SPAN style="COLOR: #0000bb">$filename</SPAN><SPAN style="COLOR: #007700">); <BR></SPAN><SPAN style="COLOR: #0000bb">imagecopymerge</SPAN><SPAN style="COLOR: #007700">(</SPAN><SPAN style="COLOR: #0000bb">$im</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">$pic</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">0</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">0</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">0</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">0</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">250</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">30</SPAN><SPAN style="COLOR: #007700">,</SPAN><SPAN style="COLOR: #0000bb">50</SPAN><SPAN style="COLOR: #007700">); <BR></SPAN><SPAN style="COLOR: #0000bb">imagejpeg</SPAN><SPAN style="COLOR: #007700">(</SPAN><SPAN style="COLOR: #0000bb">$im</SPAN><SPAN style="COLOR: #007700">); <BR></SPAN><SPAN style="COLOR: #0000bb">?></span>   <br>     </span>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317921.htmlTechArticleToday I carefully studied some related technologies of GD, and also studied the problem of Chinese garbled characters in GD. Using the GD library to output Chinese strings and calling imagestring is useless. Need to use imag...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Five tips to teach you how to solve the problem of Black Shark phone not turning on! Five tips to teach you how to solve the problem of Black Shark phone not turning on! Mar 24, 2024 pm 12:27 PM

As smartphone technology continues to develop, mobile phones play an increasingly important role in our daily lives. As a flagship phone focusing on gaming performance, the Black Shark phone is highly favored by players. However, sometimes we also face the situation that the Black Shark phone cannot be turned on. At this time, we need to take some measures to solve this problem. Next, let us share five tips to teach you how to solve the problem of Black Shark phone not turning on: Step 1: Check the battery power. First, make sure your Black Shark phone has enough power. It may be because the phone battery is exhausted

Setting up Chinese with VSCode: The Complete Guide Setting up Chinese with VSCode: The Complete Guide Mar 25, 2024 am 11:18 AM

VSCode Setup in Chinese: A Complete Guide In software development, Visual Studio Code (VSCode for short) is a commonly used integrated development environment. For developers who use Chinese, setting VSCode to the Chinese interface can improve work efficiency. This article will provide you with a complete guide, detailing how to set VSCode to a Chinese interface and providing specific code examples. Step 1: Download and install the language pack. After opening VSCode, click on the left

How to use Baidu Netdisk app How to use Baidu Netdisk app Mar 27, 2024 pm 06:46 PM

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

How to use NetEase Mailbox Master How to use NetEase Mailbox Master Mar 27, 2024 pm 05:32 PM

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? Apr 26, 2024 am 09:40 AM

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

Tips for solving Chinese garbled characters when writing txt files with PHP Tips for solving Chinese garbled characters when writing txt files with PHP Mar 27, 2024 pm 01:18 PM

Tips for solving Chinese garbled characters written by PHP into txt files. With the rapid development of the Internet, PHP, as a widely used programming language, is used by more and more developers. In PHP development, it is often necessary to read and write text files, including txt files that write Chinese content. However, due to encoding format problems, sometimes the written Chinese will appear garbled. This article will introduce some techniques to solve the problem of Chinese garbled characters written into txt files by PHP, and provide specific code examples. Problem analysis in PHP, text

How to use Xiaomi Auto app How to use Xiaomi Auto app Apr 01, 2024 pm 09:19 PM

Xiaomi car software provides remote car control functions, allowing users to remotely control the vehicle through mobile phones or computers, such as opening and closing the vehicle's doors and windows, starting the engine, controlling the vehicle's air conditioner and audio, etc. The following is the use and content of this software, let's learn about it together . Comprehensive list of Xiaomi Auto app functions and usage methods 1. The Xiaomi Auto app was launched on the Apple AppStore on March 25, and can now be downloaded from the app store on Android phones; Car purchase: Learn about the core highlights and technical parameters of Xiaomi Auto, and make an appointment for a test drive. Configure and order your Xiaomi car, and support online processing of car pickup to-do items. 3. Community: Understand Xiaomi Auto brand information, exchange car experience, and share wonderful car life; 4. Car control: The mobile phone is the remote control, remote control, real-time security, easy

How to use Dewu installment purchase How to use Dewu installment purchase Mar 24, 2024 pm 01:46 PM

How to use Dewu installment purchase? You can use the installment payment service to purchase your favorite goods in Dewu APP. Most people don’t know how to use Dewu installment purchase. Next is the Dewu installment purchase brought by the editor to users. Graphic tutorial on how to use it. Interested users can come and take a look! Dewu usage tutorial How to use Dewu installment purchase 1. First open Dewu APP and enter the main page, select your favorite product and enter the purchase page; 2. Then on the product purchase page in the picture below, click [Buy Now] in the lower right corner; 3 , then select the appropriate code number and click the price on the left; 4. Then on the order confirmation page, select [Submit Order] in the lower right corner; 5. Finally, on the payment page, check the button behind [Huabei Installment]. Just select the installment type and you’re done

See all articles