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.