How to open and verify the php gd library? (Pictures + Videos)

藏色散人
Release: 2018-10-12 13:46:11
Original
6708 people have browsed it

This article mainly introduces how to open the gd library in PHP and test and verify it.

First of all, everyone needs to understandWhat is the GD library?

The GD library is an extension library for PHP to process graphics. The GD library provides a series of APIs (Application Programming Interfaces) for processing pictures. You can use the GD library to process pictures, or generate pictures, or You can add watermarks to pictures.

On the website, the GD library is mainly used to generate thumbnails, add watermarks to pictures, generate Chinese character verification codes, or generate reports for website data, etc. to achieve some graphics-related functional effects.

The GD library is not enabled by default in PHP, so how to enable the GD library?

Step 1. In the PHP environment, open the configuration file and find the php-ini file.

How to open and verify the php gd library? (Pictures + Videos)

Step 2. Find extension=php_gd2 in the php-ini file, and then remove the semicolon in front of it.

How to open and verify the php gd library? (Pictures + Videos)

How to open and verify the php gd library? (Pictures + Videos)

Step 3. After modification, save. Restart the PHP environment and check the gd library installation information. If you can see the gd library information as shown in the figure below, it means that the GD library has been successfully opened.

There are two ways to view the gd library installation information:

1. Create a php file, and then output phpinfo(), the code is as follows:

<?php
header("Content-Type:text/html; charset=utf-8");
phpinfo();
?>
Copy after login

2 .Enter "127.0.0.1/phpinfo.php" in the browser's address bar and press Enter.

The results of these two methods are the same.

How to open and verify the php gd library? (Pictures + Videos)

After opening the gd library according to the above steps, we will verify it through a simple usage code example.

<?php
/**
 * GD库
 */
// 1.创建画布
$width = 500;
$height= 300;
$image=imagecreatetruecolor($width,$height);
// 2.创建颜色
$white=imagecolorallocate($image,255,255,255);
// 3.给画布写入字符串
imagettftext($image,40,1,200,100,$white,"123.ttf",&#39;PHP中文网&#39;);
// 4.输出或保存
header(&#39;content-type:image/jpeg&#39;);
imagejpeg($image);
Copy after login

Here we use some interfaces in the gd library to make a simple picture. The final effect is as follows:

How to open and verify the php gd library? (Pictures + Videos)

This article is about opening PHP An introduction to gd library and verification methods, I hope it will be helpful to friends in need!

If you want to learn more about PHP, you can follow the PHP Chinese website PHP Video Tutorial, everyone is welcome to refer to and learn!

The above is the detailed content of How to open and verify the php gd library? (Pictures + Videos). 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