(Advanced) PHP image processing technology-GD Library

Source: Internet
Author: User
Tags color representation
(Advanced) PHP image processing technology-GD Library details. if you need it, refer to section 1. start GD extension.

Extension = php_gd2.dll

Apache restart

2. example:

Scenario:

Create a green image of 500x300

① Create a canvas

Canvas, a type of resource-based data. Operational image resources.

Create a canvas (new)

ImageCreate (width and height) to create a canvas based on the color palette.

ImageCreateTrueColor (width, height); create a true color canvas.

Create a canvas (open) based on the image)

ImageCreateFromJPEG (image address );

ImageCreateFromPNG (image address );

ImageCreateFromGIF (image address );

② Operating canvas

Assign color: If you need to use a color on the canvas, you should first assign the color to the canvas.

Function:

Color id = imageColorAllocate (canvas, R, G, B );

Color representation:

RGB

③ Fill the canvas: fill (replace) the filled points that are continuous and of the same color)

Function:

ImageFill (canvas, fill position x, fill position Y, color logo) complete

Coordinates are used for location management:

Origin: 0, 0, the upper left corner of the canvas.

To the right, the X axis increases, and the downward Y axis increases.

Coordinates in the lower right corner: width-1, height-1

④ Output canvas

Output the processed image information in the canvas.


Typical:

1. output to the image file.

2. direct output.

Function:

ImagePNG (canvas [, file address]):

ImageJPEG ();

ImageGIF ();

If there is no second parameter, it indicates direct output.

Note: If it is directly output to the browser, you need to inform the browser that the response data type should be in PNG format:

Use the command Content-type;

A canvas can be output multiple times and in various formats

⑤ Destroy canvas resources

ImageDestroy ()


Sample code:

 


Sample code:

  

The above is (Advanced article) PHP image processing technology-the content of the GD Library. For more information, see PHP Chinese network (www.php1.cn )!

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.