


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

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
