Summary of common functions of PHP GD image processing component_PHP tutorial

WBOY
Release: 2016-07-21 15:38:47
Original
785 people have browsed it

Summary of commonly used functions of PHP image processing component GD - Overview
PHP has a series of very powerful graphics processing functions. They are all included in the GD library. These functions have basically satisfied the needs of a network application. routine image processing 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. , calligraphy is used to spend time and regret less!
This series of articles is to summarize the image processing functions of PHP for everyone. 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 needs to enable GD library support. Since this series of articles is not for rookies, 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 mutual conversion functions between image formats
3. Image creation and destruction functions
Contains functions for various ways to create images and destroy 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
writes on the image Some functions of
8. Image output function
Once 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
Current PHP environment GD library Basic information
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 information about the currently installed GD library and return an 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:

Copy code The code is as follows:

var_dump(gd_info ());
?>



The output is:
Copy code The code is as follows :

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 GD library associated with the current PHP version in the form of a bit field Supported image formats. The following results will be returned, IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM.

For example: check whether PNG is supported
Copy code The code is as follows:

if (imagetypes() & IMG_PNG) {
echo "PNG Support is enabled";
}
?>

getimagesize
Get image size
Prototype: array getimagesize ( string filename [, array &imageinfo] )

Determines the size of any image file supported by the GD library and returns the size of the image as well as the file type and an image that can be used in ordinary HTML files The height/width text string in the markup.

If the image specified by filename cannot be accessed or is not a valid image, getimagesize() will return FALSE and generate an E_WARNING level error.

Returns an array with four cells.

Index 0 contains the pixel value of the image width
Index 1 contains the pixel value of the image height
Index 2 is the tag of the image type
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.
These tags correspond to the IMAGETYPE constant added in PHP 4.3.0.
Index 3 is a text string with the content "height="yyy" width="xxx"", which can be used directly in the IMG tag.


imagecolorat
Get the color index value of a certain pixel

Prototype: int imagecolorat ( resource image, int x, int y )

Returns the image specified The color index value of the pixel at the specified position in the graphic.

If PHP was compiled with GD library 2.0 or higher and the image is a true color image, this function returns the RGB value of the point as an integer.

For example, use shifting and masking to obtain the values ​​of red, green, and blue components:
Copy code The code is as follows:

$im = ImageCreateFromPng("rockym.png");
$rgb = ImageColorAt($im, 100, 100);
$r = ( $rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
?>


imagesx/imagesy
These two functions are relatively simple. The prototype of obtaining image width/height
is as follows:
int imagesx ( resource image )
int imagesy ( resource image )

Returns the width/height of the image represented by image.

Reprinted from http://www.sourcejoy.com/

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321669.htmlTechArticleSummary of common functions of PHP image processing component GD - Overview PHP has a series of very powerful graphics processing functions, they all Uniformly included in the GD library, these functions have basically satisfied a network...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template