The common function Summary _php technique of PHP GD image processing component

Source: Internet
Author: User
PHP Image processing component 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 satisfied a network application of the conventional image processing requirements, and very simple to use.
And we have a lot of PHP friends (including me) all think that these functions are not very commonly used, are lazy to study or understand these functions, and when facing the image processing aspects of things, and very vacant, the book when the side hate less Ah!
This series of articles is to give you a summary of the PHP image processing functions, do not require mastery, just want to let you have a general impression of these functions, at least, there are image processing aspects of the discussion or problems, the mind can think of these functions, so that everyone in the solution when they can do it! A little more nonsense!
This is the opening, so first and these functions related to the GD library, as well as the classification of functions, after the article will be based on the classification, to specifically say.

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

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

This is the beginning of the story, and the next few are categorized into these functions.

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

Here is a specific statement!

Gd_info
To obtain information about the currently installed GD library, return the array
Array key meaning:
GD Version
String value. Describes the version of the installed LIBGD.
Freetype Support
A Boolean value. TRUE if Freetype support is installed.
Freetype linkage
String value. Describes the method for Freetype connections. The value may be: ' With FreeType ', ' with TTF library ' and ' with Unknown library '. This unit is only defined when 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 support is included for a read GIF image.
GIF Create Support
A Boolean value. TRUE if support is included for creating GIF images.
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 Code code as follows:

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



The output is:
Copy Code code 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 format supported by the GD library associated with the current PHP version in bit-field mode. The following results will be returned, Img_gif | img_jpg | Img_png | img_wbmp| img_xpm.

For example: Check to see if PNG is supported
Copy Code code as follows:

<?php
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 the tag in the normal HTML file.

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

Returns an array of four cells.

Index 0 pixel values that contain the width of the image
Index 1 pixel values that contain the height of the image
Index 2 is the mark of the image type
1 = gif,2 = jpg,3 = png,4 = swf,5 = psd,6 = The 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 contents "height=" yyy "width=" xxx, which can be used directly for 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 shape specified by image.

If PHP compiles with a version of 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 the shift mask to obtain the values of the respective components of red, green, and blue:
Copy Code code as follows:

<?php
$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, 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 that is represented by 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.