Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP Image Processing

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 extension
image_type_to_mime_type() Return the MIME type of the image
image2wbmp() Output WBMP image
imageaffine() Return the image after affine transformation
imageaffinematrixconcat() Concatenate two matrices
imageaffinematrixget() Get matrix
imagealphablending() Set the blending mode of the image
imageantialias() Whether to use the antialias feature
imagearc() Draw an elliptical arc
imagechar() Write a horizontal character
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 certain pixel
imagecolorclosest() Get the color index value closest to the specified color
imagecolorclosestalpha() Get the color index closest to the specified color plus transparency
imagecolorclosesthwb() Get the index of the grayscale (black and white) color 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. Please 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

You can use the gd_info() function to view information about the currently installed GD library:



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)

}