PHP image processing


PHP provides a wealth of image processing functions, mainly including:

FunctionDescription
gd_info()Get information about the currently installed GD library
getimagesize()Get image information
getimagesizefromstring()Get image information
image_type_to_extension()Get image suffix
image_type_to_mime_type()Return the MIME type of the image
image2wbmp()Output WBMP image
imageaffine()Return the image after affine transformation
imageaffinematrixconcat()Connect two matrices
imageaffinematrixget()Get the matrix
imagealphablending()Set the color mixing mode of the image
imageantialias()Whether to use the antialias function
imagearc()Draw an elliptical arc
imagechar()Write horizontal characters
imagecharup()Draw a character vertically
imagecolorallocate()Assigns a color to an image
imagecolorallocatealpha()is one Assign color and transparency to an image
imagecolorat()Get the color index value of a certain pixel
imagecolorclosest()Get the index value of the color closest to the specified color
imagecolorclosestalpha()Get the index value of the color closest to the specified color plus transparency Index
imagecolorclosesthwb()Get the black and white index of the chromaticity closest to the specified color
imagesx (), imagesy()Get image width and height

GD library

Use PHP image processing function, need to load GD support library. Please make sure php.ini has loaded the GD library:

On Window server:

extension = php_gd2.dll

On Linux and Mac systems:

extension = php_gd2.so

Use the gd_info() function to view the currently installed GD library information:

<?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)
}