Home > Article > Daily Programming > How to open and verify the php gd library? (Pictures + Videos)
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.
Step 2. Find extension=php_gd2 in the php-ini file, and then remove the semicolon in front of it.
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(); ?>
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.
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",'PHP中文网'); // 4.输出或保存 header('content-type:image/jpeg'); imagejpeg($image);
Here we use some interfaces in the gd library to make a simple picture. The final effect is as follows:
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!