Summary of common functions of PHP GD image processing Components _php Tutorial

Source: Internet
Author: User
PHP Image processing Components GD's common function summary--Overview
PHP has a series of very powerful graphics processing functions, they are uniformly included in the GD library, these functions have basically met a network application of the general image processing requirements, and the use is very simple.
And we have a lot of PHP friends (including me) think that these functions are not very common, are lazy to study or understand these functions, and when faced with the image processing aspects of the time, and very vacant, the book Road when the party hates less Ah!
This series of articles is to give you a summary of the PHP image processing functions, do not require mastery, only hope that you can have a general impression of these functions, at least, there is a discussion of the image processing or problems, the mind can think of these functions, so that we think the solution when you can do it! There's a lot of crap!
This is the beginning, so first of these functions related to the GD library, as well as the classification of functions, after the article will be based on the classification, to say specifically.

PHP functions are in the GD library, to use the GD Library, PHP to open the GD library support, due to consider this series of articles is not the rookie so, do not talk about how to open the support of the GD library.

PHP's image processing functions are roughly divided into several categories:
1. Basic information functions
Mainly is the image type, the image width is high, the library version and so on the basic function.
2. Image conversion function
Contains the reciprocal conversion functions between image formats
3. Image creation and destruction functions
Functions that contain images in various ways to create images, and functions to destroy image processing related resources
4. Drawing Operation function
Includes drawing related functions such as drawing lines, drawing circles, drawing squares, etc.
5. Image manipulation functions
Functions for performing some effect processing on an image
6. Image Setting function
Set some parameters of the image, such as: the width of the line, the image is transparent Ah, whether true color ah, etc.
7. Image Text function
Some functions for writing on an image
8. Image Output function
The image is ready, you have to output it, these functions are used to output, where is the output? browsers, files, etc.

This is the beginning of the story, the next few will be classified as these functions.

PHP Image processing component GD's common function summary--basic information function
Basic information functions are mainly as follows:
Gd_info
Basic information of the current PHP environment GD library
Imagetypes
Supported Image types
GetImageSize
Get the size of an image
Imagecolorat
Gets the color index value of a pixel of an image
Imagesx
Get Image width
Imagesy
Get Image Height

Here is a detailed statement!

Gd_info
Get information about the currently installed GD library and return the array
Array key meaning:
GD Version
A string value. Describes the version of the LIBGD that was installed.
Freetype Support
A Boolean value. True if Freetype support is installed.
Freetype Linkage
A string value. Describes the methods for Freetype connections. The values may be: ' With FreeType ', ' with TTF library ' and ' with Unknown library '. This unit is defined only if the value of Freetype support is TRUE.
T1lib Support
A Boolean value. True if T1lib support is included.
GIF Read Support
A Boolean value. TRUE If there is support for reading a GIF image.
GIF Create Support
A Boolean value. TRUE if support for creating a GIF image is included.
JPG Support
A Boolean value. True if JPG support is included.
PNG Support
A Boolean value. True if PNG support is included.
WBMP Support
A Boolean value. True if WBMP support is included.
XBM Support
A Boolean value. True if XBM support is included.

Such as:
Copy CodeThe code is as follows:
Var_dump (Gd_info ());
?>



The output is:
Copy CodeThe code is as follows:
Array (9) {
["GD Version"]=>
String "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 type of image 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 as a bit field. The following results will be returned, Img_gif | img_jpg | Img_png | img_wbmp| img_xpm.

such as: Check whether PNG is supported
Copy CodeThe code is as follows:
if (Imagetypes () & Img_png) {
echo "PNG support is enabled";
}
?>

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

Determine 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 markup in normal HTML files.

If the image specified by filename cannot be accessed or is not a valid image, GetImageSize () returns false and produces an e_warning level error.

Returns an array with four cells.

Index 0 A pixel value that contains the width of the image
Index 1 A pixel value that contains the height of the image
Index 2 is a marker 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, one = jpx,12 = jb2,13 = swc,14 = iff,15 = wbmp,16 = XBM.
These tags correspond to the newly added IMAGETYPE constants of PHP 4.3.0.
Index 3 is a text string with the content "height=" yyy "width=" xxx ", which can be used directly with the IMG tag.


Imagecolorat
Gets the color index value of a pixel

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

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

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

For example, use the shift mask to obtain the values of the respective components of red, green, and blue:
Copy CodeThe code is as follows:
$im = Imagecreatefrompng ("Rockym.png");
$rgb = Imagecolorat ($im, 100, 100);
$r = ($rgb >>) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
?>


Imagesx/imagesy
These two functions are relatively simple and get the image width/height
The prototype 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/

http://www.bkjia.com/PHPjc/321669.html www.bkjia.com true http://www.bkjia.com/PHPjc/321669.html techarticle PHP Image processing Components GD's common function summary--Overview PHP has a series of very powerful graphics processing functions, they are unified in the GD library, these functions have basically met a net ...

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