Summary of common functions of the php gd image processing component

Source: Internet
Author: User
Tags reading gif

Summary of common functions of PHP image processing component GD -- Overview
PHP has a series of powerful graphic processing functions that are uniformly included in the GD library. These functions have basically met the conventional image processing requirements of a network application and are easy to use.
Many of our PHP-related friends (including me) think that these functions are not very commonly used. They are too lazy to study or understand these functions, however, when it comes to image processing, I am very confused. I hate it a little!
These articles in this series summarize the image processing functions of PHP. They do not need to be mastered. They only hope to give you 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, so that you can be confident in your solutions! A little nonsense!
This article is the beginning, so we will first look at the GD library related to these functions, as well as the classification of functions. The subsequent articles will be specific Based on the classification.

PHP functions are all in the GD library. To use the GD library, PHP must enable the GD library support. This series of articles is not about cainiao, we will not discuss how to enable the support for the GD library.

PHP image processing functions are divided into several categories:
1. Basic information functions
The most basic functions are image types, image width and height, and library versions.
2. Image conversion functions
Contains mutual conversion functions between image formats
3. Image creation and destruction Functions
Functions that contain various image creation methods and functions that destroy image processing-related resources
4. Graphic operation functions
Including functions related to drawing, picturesque line, circle, and square
5. Image operation functions
Functions for processing the effects of images
6. Image setting function
Set some image parameters, such as the width of the draw line, whether the image is transparent, and whether the image is really colorful.
7. Image Text Functions
Functions for writing Images
8. image output functions
After the image is ready, you have to output it. These functions are used for output. Where is the output? Browsers, files, etc.

Let's talk about these functions in the beginning. The next few articles will talk about these functions in classification.

Summary of common functions of PHP image processing component GD-basic information functions
Basic information functions include the following:
Gd_info
Basic information of the current GD library in the PHP Environment
Imagetypes
Supported image types
Getimagesize
Obtains the size of an image.
Imagecolorat
Obtains the color index value of a certain pixel of an image.
Imagesx
Get Image Width
Imagesy
Get Image Height

The following is a detailed description!

Gd_info
Obtains information about the currently installed GD library and returns an array.
Meaning of the array key:
GD Version
String value. Describes the version of libgd installed.
Freetype Support
Boolean value. TRUE if Freetype is installed.
Freetype Linkage
String value. Describes how to connect Freetype. The values may be: 'with freetype', 'with TTF library', and 'with unknown library '. This unit is defined only when the value of Freetype Support is TRUE.
T1Lib Support
Boolean value. TRUE if T1Lib is supported.
GIF Read Support
Boolean value. TRUE if it supports reading GIF images.
GIF Create Support
Boolean value. TRUE is supported if a GIF image is created.
JPG Support
Boolean value. TRUE if JPG is supported.
PNG Support
Boolean value. TRUE if PNG is supported.
WBMP Support
Boolean value. TRUE if WBMP is supported.
XBM Support
Boolean value. TRUE if XBM is supported.

For example:
Copy codeThe Code is as follows:
<? Php
Var_dump (gd_info ());
?>



Output:
Copy codeThe 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 image formats supported by the GD library associated with the current PHP version in the form of bits. The following result is returned: IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM.

For example, check whether PNG is supported.
Copy codeThe Code is as follows:
<? Php
If (imagetypes () & IMG_PNG ){
Echo "PNG Support is enabled ";
}
?>

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

Measure the size of the image file supported by any GD library and return the size of the image as well as the file type and a height/width text string that can be used in the mark of a common HTML file.

If you cannot access the image specified by filename or the image is not valid, getimagesize () returns FALSE and generates an E_WARNING error.

Returns an array with four units.

Index 0 contains the pixel value of the Image Width
Index 1 contains the pixel value of the Image Height
Index 2 is a mark 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 newly added IMAGETYPE constant in PHP 4.3.0.
Index 3 is a text string with the content "height =" yyy "width =" xxx "and can be directly used for IMG marking.


Imagecolorat
Obtain the color index value of a certain Pixel

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

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

If the GD library 2.0 or later version is added during PHP compilation and the image is a real color image, this function returns the RGB value of this point as an integer.

For example, the values of the respective components of red, green, and blue are obtained using shift and mask:
Copy codeThe Code is as follows:
<? Php
$ 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 to obtain the image width/height.
The prototype is as follows:
Int imagesx (resource image)
Int imagesy (resource image)

Returns the width/height of the image.

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.