Table of Contents
Use the GD library to generate images with shadow text
Home Backend Development PHP Tutorial Use GD library to generate images with shadow text_PHP tutorial

Use GD library to generate images with shadow text_PHP tutorial

Jul 13, 2016 am 09:59 AM
main use picture bring Library letter article method generate of shadow

Use the GD library to generate images with shadow text

This article mainly introduces the method of using the GD library to generate images with shadow text. It is very detailed and recommended to everyone. Friends in need can refer to it

I recently used the GD library to generate images for WeChat public accounts. I studied the generation of text shadow effects in the GD library and also discovered the power of the GD library.

The GD library is an extension library for PHP to process graphics. The GD library provides a series of APIs for processing images. You can use the GD library to process images or generate images. On websites, the GD library is usually used to generate thumbnails, add watermarks to images, generate Chinese character verification codes, or generate reports on website data.

The installation of the GD library is available online, and many virtual spaces now support it, so I won’t go into details here. Below, I will introduce how to use the GD library through examples of my actual application code and related comments.

Original picture:

使用GD库生成带阴影文字的图片    帮客之家

Generate renderings:

The code is as follows:

 ?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

$str="北京";

$str2= "空气质量:轻度污染";

// 通过图片生成一个对象$im

$im = imagecreatefromjpeg("images/3.jpg");

//载入字体zt.ttf

$fnt = "zt.ttf";

//创建颜色,用于文字字体的白和阴影的黑

$white=imagecolorallocate($im,222,229,207);

$black=imagecolorallocate($im,50,50,50);

//创建关于相对图片位置的函数,方便调用

$top=100;

$left=60;

$top2=170;

//在图片中添加文字,imagettftext (image,size,angle, x, y,color,fontfile,text)

imagettftext($im,41, 0, $left 1, $top 1, $black, $fnt, $str);

imagettftext($im,41, 0, $left, $top, $white, $fnt, $str);

imagettftext($im,43, 0, $left 1,$top2 1 , $black, $fnt, $str2);

imagettftext($im,43, 0, $left,$top2, $white, $fnt, $str2);

//将$im输出

ImageJpeg($im);

//销毁$im对象

ImageDestroy($im);

1

2

3

4

5

6

7

8

9

10

11
12 13

1415 16 17 18 19 20
21
22
$str="Beijing"; $str2= "Air Quality: Mild Pollution"; // Generate an object $im from the image $im = imagecreatefromjpeg("images/3.jpg"); //Load font zt.ttf $fnt = "zt.ttf"; //Create colors, white for text font and black for shadow $white=imagecolorallocate($im,222,229,207); $black=imagecolorallocate($im,50,50,50); //Create a function about relative image position for easy calling $top=100; $left=60; $top2=170; //Add text to the image, imagettftext (image, size, angle, x, y, color, fontfile, text) imagettftext($im,41, 0, $left 1, $top 1, $black, $fnt, $str); imagettftext($im,41, 0, $left, $top, $white, $fnt, $str); imagettftext($im,43, 0, $left 1,$top2 1 , $black, $fnt, $str2); imagettftext($im,43, 0, $left,$top2, $white, $fnt, $str2); //Output $im ImageJpeg($im); //Destroy the $im object ImageDestroy($im);
Next, let’s explain in detail: Imagettftext (image, size, angle, x, y, color, fontfile, text) Imagettftext() draws the string text onto the image represented by the image, starting from the coordinates x, y (the upper left corner is 0, 0), the angle is angle, the color is color, and the TrueType font specified by fontfile is used document. The coordinates represented by x, y define the basic point of the first character approximately at the lower left corner of the character.  angle is expressed in degrees, with 0 degrees meaning the text is read from left to right and higher values ​​meaning counter-clockwise (i.e. a value of 90 means the text is read from bottom to top).  fontfile is the file name of the TrueType font you want to use. Text is a text string that can contain UTF-8 character sequences. Color is the index value of the color. The above is the entire content of this article, I hope you all like it. http://www.bkjia.com/PHPjc/975123.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/975123.htmlTechArticleUsing the GD library to generate images with shadow text. This article mainly introduces the use of the GD library to generate images with shadow text. The method is very detailed. I recommend it to everyone. Friends who need it can refer to it...
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)

How to make round pictures and text in ppt How to make round pictures and text in ppt Mar 26, 2024 am 10:23 AM

First, draw a circle in PPT, then insert a text box and enter text content. Finally, set the fill and outline of the text box to None to complete the production of circular pictures and text.

How to write a novel in the Tomato Free Novel app. Share the tutorial on how to write a novel in Tomato Novel. How to write a novel in the Tomato Free Novel app. Share the tutorial on how to write a novel in Tomato Novel. Mar 28, 2024 pm 12:50 PM

Tomato Novel is a very popular novel reading software. We often have new novels and comics to read in Tomato Novel. Every novel and comic is very interesting. Many friends also want to write novels. Earn pocket money and edit the content of the novel you want to write into text. So how do we write the novel in it? My friends don’t know, so let’s go to this site together. Let’s take some time to look at an introduction to how to write a novel. Share the Tomato novel tutorial on how to write a novel. 1. First open the Tomato free novel app on your mobile phone and click on Personal Center - Writer Center. 2. Jump to the Tomato Writer Assistant page - click on Create a new book at the end of the novel.

How to solve the problem of automatically saving pictures when publishing on Xiaohongshu? Where is the automatically saved image when posting? How to solve the problem of automatically saving pictures when publishing on Xiaohongshu? Where is the automatically saved image when posting? Mar 22, 2024 am 08:06 AM

With the continuous development of social media, Xiaohongshu has become a platform for more and more young people to share their lives and discover beautiful things. Many users are troubled by auto-save issues when posting images. So, how to solve this problem? 1. How to solve the problem of automatically saving pictures when publishing on Xiaohongshu? 1. Clear the cache First, we can try to clear the cache data of Xiaohongshu. The steps are as follows: (1) Open Xiaohongshu and click the "My" button in the lower right corner; (2) On the personal center page, find "Settings" and click it; (3) Scroll down and find the "Clear Cache" option. Click OK. After clearing the cache, re-enter Xiaohongshu and try to post pictures to see if the automatic saving problem is solved. 2. Update the Xiaohongshu version to ensure that your Xiaohongshu

How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) May 01, 2024 pm 12:01 PM

Unfortunately, people often delete certain contacts accidentally for some reasons. WeChat is a widely used social software. To help users solve this problem, this article will introduce how to retrieve deleted contacts in a simple way. 1. Understand the WeChat contact deletion mechanism. This provides us with the possibility to retrieve deleted contacts. The contact deletion mechanism in WeChat removes them from the address book, but does not delete them completely. 2. Use WeChat’s built-in “Contact Book Recovery” function. WeChat provides “Contact Book Recovery” to save time and energy. Users can quickly retrieve previously deleted contacts through this function. 3. Enter the WeChat settings page and click the lower right corner, open the WeChat application "Me" and click the settings icon in the upper right corner to enter the settings page.

How to make ppt pictures appear one by one How to make ppt pictures appear one by one Mar 25, 2024 pm 04:00 PM

In PowerPoint, it is a common technique to display pictures one by one, which can be achieved by setting animation effects. This guide details the steps to implement this technique, including basic setup, image insertion, adding animation, and adjusting animation order and timing. Additionally, advanced settings and adjustments are provided, such as using triggers, adjusting animation speed and order, and previewing animation effects. By following these steps and tips, users can easily set up pictures to appear one after another in PowerPoint, thereby enhancing the visual impact of the presentation and grabbing the attention of the audience.

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.

The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs) The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs) May 04, 2024 pm 06:01 PM

Mobile games have become an integral part of people's lives with the development of technology. It has attracted the attention of many players with its cute dragon egg image and interesting hatching process, and one of the games that has attracted much attention is the mobile version of Dragon Egg. To help players better cultivate and grow their own dragons in the game, this article will introduce to you how to hatch dragon eggs in the mobile version. 1. Choose the appropriate type of dragon egg. Players need to carefully choose the type of dragon egg that they like and suit themselves, based on the different types of dragon egg attributes and abilities provided in the game. 2. Upgrade the level of the incubation machine. Players need to improve the level of the incubation machine by completing tasks and collecting props. The level of the incubation machine determines the hatching speed and hatching success rate. 3. Collect the resources required for hatching. Players need to be in the game

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

See all articles