Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

PHP image processing


May 11, 2021 PHP


Table of contents


PHP image processing

PHP provides a wealth of image processing functions, including:

Function Describe
gd_info() Get information about the currently installed GD library
getimagesize() Get image information
imagesx() 、imagesy() Gets the width and height of the image
getimagesizefromstring() Get image information
image_type_to_extension() Get the picture suffix
image2wbmp() Output WBMP pictures
imageaffinematrixconcat() Connect the two matrices
imageaffinematrixget() Gets the matrix
image_type_to_mime_type() Returns the MIME type of the image
imageaffine() Returns an image that has been a2formed
imagealphablending() Sets the process mode of the image
imagecolorallocate() Assign color to an image
imagecolorallocatealpha() Assign color and transparency to an image
imagecolorat() Get the color index value for a pixel
imagecolorclosest() Get the index value of the color closest to the specified color
imagecolorclosestalpha() Get an index of the colors closest to the specified color transparency
imagecolorclosesthwb() Get a black-and-white index of the color closest to the specified color
imageantialias() Whether anti-aliasing is used
imagearc() Draw an elliptical arc
imagechar() Write out landscape characters
imagecharup() Draw a character vertically

GD library

Using the PHP image processing function, you need to load the GD support library. Make sure the php .ini the GD library is loaded:

On the Window server:

extension = php_gd2.dll

On Linux and Mac systems:

extension = php_gd2.so

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