Introduction to the imagecreate and imagedestroy functions of PHP image processing, imagedestroy

Source: Internet
Author: User
Tags image identifier

Introduction to the imagecreate and imagedestroy functions of PHP image processing, imagedestroy

When using the GD library of PHP to process images, you must manage the canvas. Creating a canvas is to open up a storage area in the memory. In the future, all operations on the image in PHP are based on this canvas, and the canvas is an image resource. In PHP, you can use the imagecrete () and imageCreateTrueColor () functions to create the specified canvas. The two functions are used to create a canvas of the specified size. Their prototype is as follows:
Copy codeThe Code is as follows:
Resource imagecreate (int $ x_size, int $ y_size) // create a palette-based image.
Resource imagecreatetruecolor (int $ x_size, int $ y_size) // create a true color image

Although both functions can create a new canvas, the total number of colors that each function can hold is different. The imageCreate () function allows you to create an image based on a normal color palette. Generally, the image supports 256 colors. The imageCreateTrueColor () function can create a real-color image, but this function cannot be used in GIF file format. After the canvas is created, an image identifier is returned, representing a blank image reference handle with a width of $ x_size and a height of $ y_size. In the subsequent drawing process, you need to use the resource type handle. For example, you can call the imagesx () and imagesy () functions to obtain the image size. The Code is as follows:
Copy codeThe Code is as follows:
<? Php
$ Img = imagecreatetruecolor (300,200); // create a 300*200 canvas
Echo imagesx ($ img); // The width of the output canvas is 300
Echo imagesy ($ img); // The height of the output canvas is 200
?>

In addition, if the reference handle of the canvas is no longer used, the resource must be destroyed to release the memory and the storage unit of the image. The canvas destruction process is very simple. You can call the imagedestroy () function. The syntax format is as follows:
Copy codeThe Code is as follows:
Bool imagedestroy (resource $ image) // destroy an image

If the method is called successfully, the memory associated with the parameter $ image is released. The parameter $ image is the image identifier returned by the image creation function.

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.