PHP Image Processing
PHP provides a rich set of image processing functions, mainly including:
| Function | Description |
|---|---|
| gd_info() | Get information about the currently installed GD library |
| getimagesize() | Get image information |
| getimagesizefromstring() | Get image information |
| image_type_to_extension() | Get image file extension |
| image_type_to_mime_type() | Return the MIME type of an image |
| image2wbmp() | Output WBMP image |
| imageaffine() | Return the image after affine transformation |
| imageaffinematrixconcat() | Concatenate two matrices |
| imageaffinematrixget() | Get matrix |
| imagealphablending() | Set image blending mode |
| imageantialias() | Whether to use antialiasing |
| imagearc() | Draw elliptical arc |
| imagechar() | Write a character horizontally |
| imagecharup() | Draw a character vertically |
| imagecolorallocate() | Allocate a color for an image |
| imagecolorallocatealpha() | Allocate a color and transparency for an image |
| imagecolorat() | Get the color index value of a pixel |
| imagecolorclosest() | Get the index of the color closest to the specified color |
| imagecolorclosestalpha() | Get the index of the color closest to the specified color with transparency |
| imagecolorclosesthwb() | Get the black-and-white index of the shade closest to the specified color |
| imagesx() 、imagesy() | Get image width and height |
GD Library
To use PHP image processing functions, you need to load the GD support library. Make sure php.ini has the GD library loaded:
On Windows servers:
extension = php_gd2.dll
On Linux and Mac systems:
extension = php_gd2.so
Use the gd_info() function to view information about the currently installed GD library:
<?php var_dump(gd_info()); ?>
The output is roughly as follows:
array(12) {
["GD Version"]=>
string(26) "bundled (2.1.0 compatible)"
["FreeType Support"]=>
bool(true)
["FreeType Linkage"]=>
string(13) "with freetype"
["T1Lib Support"]=>
bool(false)
["GIF Read Support"]=>
bool(true)
["GIF Create Support"]=>
bool(true)
["JPEG Support"]=>
bool(true)
["PNG Support"]=>
bool(true)
["WBMP Support"]=>
bool(true)
["XPM Support"]=>
bool(false)
["XBM Support"]=>
bool(true)
["JIS-mapped Japanese Font Support"]=>
bool(false)
}
Other extensions