Summary of common functions of PHPGD image processing component _ PHP Tutorial

Source: Internet
Author: User
Tags reading gif
Summary of common functions of the PHPGD image processing component. Summary of common functions of PHP image processing component GD-Overview PHP has a series of powerful graph processing functions which are included in the GD Library. these functions have basically met the needs of a network. 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:

The code is as follows:


Var_dump (gd_info ());
?>




Output:

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 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.

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])

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 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:

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 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/

PHP has a series of powerful graphic processing functions, all of which are included in the GD Library. these functions have basically met the needs of a network...

Related Article

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.