


Summary of common functions of PHP GD image processing components
Summary of common functions of PHP image processing component GD - Overview
PHP has a series of very powerful graphics processing functions, which are all included in the GD library. These functions have basically satisfied the conventional image processing of a network application. requirements and is very simple to use.
Many of our PHP friends (including me) think that these functions are not very commonly used anyway, and are too lazy to study or understand these functions. When faced with image processing, they are at a loss. , the time spent in calligraphy is too short!
This series of articles is to summarize PHP's image processing functions for you. It does not require mastery. I just hope that you can have a general impression of these functions. At the very least, when you have discussions or questions about image processing , you can think of these functions in your mind, so that everyone can be confident when thinking of solutions! There's a lot of nonsense!
This article is the beginning, so let's first talk about the GD library related to these functions, as well as the classification of the functions. The following articles will be detailed according to the classification.
PHP functions are all in the GD library. If you want to use the GD library, PHP must enable GD library support. Since this series of articles is not for novices, I will not talk about how to enable GD library support. La.
PHP’s image processing functions are roughly divided into several categories:
1. Basic information functions
Mainly the most basic functions such as image type, image width and height, and library version.
2. Image conversion function
Contains functions for converting between image formats
3. Image creation and destruction functions
Contains functions for various ways to create images and destroys image processing related resources Functions
4. Drawing operation functions
Include drawing-related functions, such as drawing lines, circles, squares, etc.
5. Image operation functions
Functions that perform some effect processing on images
6. Image setting function
Set some parameters of the image, such as: the width of the drawn line, whether the image is transparent, whether it is true color, etc.
7. Image text function
Write on the image Some functions
8. Image output function
After the image is done, it must be output. These functions are used for output. Where should it be output? Browsers, files, etc.
I’ll talk about these at the beginning, and the next few articles will talk about these functions by category.
Summary of commonly used functions of PHP image processing component GD - basic information functions
Basic information functions mainly include the following:
gd_info
Basic information of the current PHP environment GD library
imagetypes
Supported image types
getimagesize
Get the size of an image
imagecolorat
Get the color index value of a certain pixel of the image
imagesx
Get the image width
imagesy
Get the image height
Let’s talk about it in detail below!
gd_info
Get the information of the currently installed GD library and return the array
Array key meaning:
GD Version
string value. Describes the version of libgd installed.
Freetype Support
boolean value. TRUE if Freetype support is installed.
Freetype Linkage
string value. Describes Freetype connection methods. Possible values are: 'with freetype', 'with TTF library' and 'with unknown library'. This unit is only defined when Freetype Support is TRUE.
T1Lib Support
boolean value. TRUE if T1Lib support is included.
GIF Read Support
boolean value. TRUE if support for reading GIF images is included.
GIF Create Support
boolean value. TRUE if support for creating GIF images is included.
JPG Support
boolean value. TRUE if JPG support is included.
PNG Support
boolean value. TRUE if PNG support is included.
WBMP Support
boolean value. TRUE if WBMP support is included.
XBM Support
boolean value. TRUE if XBM support is included.
For example:
<?php var_dump(gd_info()); ?>
The output is:
array(9) { ["GD Version"]=> string(24) "bundled (2.0 compatible)" ["FreeType Support"]=> bool(false) ["T1Lib Support"]=> bool(false) ["GIF Read Support"]=> bool(true) ["GIF Create Support"]=> bool(false) ["JPG Support"]=> bool(false) ["PNG Support"]=> bool(true) ["WBMP Support"]=> bool(true) ["XBM Support"]=> bool(false) }
imagetypes
Returns the image types supported by the current PHP version
Prototype: int imagetypes ( void )
This function returns the image format supported by the GD library associated with the current PHP version in a bit field. The following results will be returned, IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM.
For example: check whether PNG is supported
<?php if (imagetypes() & IMG_PNG) { echo "PNG Support is enabled"; } ?>
getimagesize
取得图像大小
原型:array getimagesize ( string filename [, array &imageinfo] )
测定任何GD库支持的图像文件的大小并返回图像的尺寸以及文件类型和一个可以用于普通 HTML 文件中 标记中的 height/width 文本字符串。
如果不能访问 filename 指定的图像或者其不是有效的图像,getimagesize() 将返回 FALSE 并产生一条 E_WARNING 级的错误。
返回一个具有四个单元的数组。
索引 0 包含图像宽度的像素值
索引 1 包含图像高度的像素值
索引 2 是图像类型的标记
1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP,7 = TIFF(intel byte order),8 = TIFF(motorola byte order),9 = JPC,10 = JP2,11 = JPX,12 = JB2,13 = SWC,14 = IFF,15 = WBMP,16 = XBM。
这些标记与 PHP 4.3.0 新加的 IMAGETYPE 常量对应。
索引 3 是文本字符串,内容为“height="yyy" width="xxx"”,可直接用于 IMG 标记。
imagecolorat
取得某像素的颜色索引值
原型:int imagecolorat ( resource image, int x, int y )
返回 image 所指定的图形中指定位置像素的颜色索引值。
如果 PHP 编译时加上了 GD 库 2.0 或更高的版本并且图像是真彩色图像,则本函数以整数返回该点的 RGB 值。
如,用移位加掩码来取得红,绿,蓝各自成分的值:
<?php $im = ImageCreateFromPng("rockym.png"); $rgb = ImageColorAt($im, 100, 100); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; ?>
这两个函数比较简单,取得图像宽度/高度
原型如下:
int imagesx ( resource image )
int imagesy ( resource image )
返回 image 所代表的图像的宽度/高度。
更多PHP GD 图像处理组件的常用函数总结相关文章请关注PHP中文网!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.
