Introduction to imagecreate and imagedestroy functions in PHP image processing, imagedestroy_PHP tutorial

WBOY
Release: 2016-07-13 10:13:51
Original
1070 people have browsed it

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

When using PHP's GD library to process images, the canvas must be managed. Creating a canvas is to open up a storage area in the memory. All future operations on images in PHP will be based on this canvas, which is an image resource. In PHP, you can use the imagecrete() and imageCreateTrueColor() functions to create a specified canvas. The functions of these two functions are the same. They both create a canvas of a specified size. Their prototypes are as follows:

Copy code The code is as follows:

resource imagecreate(int $x_size,int $y_size) //Create a new palette-based image
resource imagecreatetruecolor(int $x_size,int $y_size) //Create a new true color image

Although both functions can create a new canvas, the total number of colors they can hold is different. The imageCreate() function can create an image based on a common palette, usually supporting 256 colors. The imageCreateTrueColor() function can create a true color image, but this function cannot be used in the GIF file format. When 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 subsequent drawing processes, you need to use the handle of this resource type. For example, you can get the size of an image by calling the imagesx() and imagesy() functions. The code looks like this:
Copy code The code is as follows:

$img = imagecreatetruecolor(300,200);//Create a 300*200 canvas
echo imagesx($img);//Output canvas width 300
echo imagesy($img);//Output canvas height 200
?>

In addition, if the reference handle of the canvas is no longer used, this resource must be destroyed to release the memory and the storage unit of the image. The canvas destruction process is very simple and can be achieved by calling the imagedestroy() function. Its syntax format is as follows:
Copy code The code is as follows:

bool imagedestroy(resource $image) //Destroy an image

If the method call is successful, the memory associated with the parameter $image will be released. The parameter $image is the image identifier returned by the image creation function.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/914043.htmlTechArticleIntroduction to the imagecreate and imagedestroy functions of PHP image processing, imagedestroy When using PHP's GD library to process images, the canvas must be manage. Creating a canvas is to open up a space in memory...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!