When working with an image using the PHP GD library, you must manage the canvas. Creating a canvas is a piece of storage in memory, and in the future all operations on the image in PHP are based on the fabric, and Parliament is an image resource. In PHP, you can use Imagecrete () and Imagecreatetruecolor () two functions to create a specified canvas. The function of these two functions is consistent, is to create a specified size of the canvas, their prototype 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 that each can hold is different. The Imagecreate () function creates an image based on a normal palette, typically supporting 256 colors. The Imagecreatetruecolor () function can create a true color image, but the 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. A handle to this resource type is required for subsequent drawing processes. For example, you can get the size of an image by calling Imagesx () and Imagesy () two functions. The code looks like this:
<?php$img = Imagecreatetruecolor (300,200);//Create a 300*200 canvas echo imagesx ($IMG);//Output Canvas width 300echo imagesy ($img);// Output Canvas Height 200?>
Also, if the reference handle to the canvas is no longer in use, be sure to destroy the resource, freeing the memory with the storage unit for the image. The process of destroying the canvas is very simple and can be achieved by invoking the Imagedestroy () function. Its syntax format is as follows:
BOOL Imagedestroy (Resource $image) //Destroy an image
If the method call succeeds, the memory associated with the parameter $image is freed. Where parameter $image is the image identifier returned by the image creation function.
read more about PHP image processing Imagecreate, Imagedestroy functions related articles Please pay attention to topic.alibabacloud.com!