Summary of common functions of PHP GD image processing components

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:

<?php Var_dump (Gd_info ());?>

The output is:

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

<?php if (Imagetypes () & img_png) {echo "PNG support is enabled";}?>

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

To determine the image files supported by any GD library Size and returns the size of the image as well as the file type and a height/width text string that can be used in the tag in the normal HTML file.

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

returns an array with four cells.

Index 0 contains the pixel value of the image width
Index 1 pixel value containing 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 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 image specified The color index value of the pixel in the specified position in the drawing.

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

For example, use the shift mask to get the values of the respective components of red, green, and blue:

<?php $im = imagecreatefrompng ("Rockym.png"); $rgb = Imagecolorat ($im, 100, 100); $r = ($rgb >>) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF;?>

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.

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.