Introduction to the Imagecreate and Imagedestroy functions of PHP image processing _php skills

Source: Internet
Author: User
Tags image identifier

When working with images using the GD Library of PHP, you must manage the canvas. Creating a canvas is in memory to open a piece of storage area, later in PHP in the image of all operations are based on this cloth processing, Parliament is an image resource. In PHP, you can use the Imagecrete () and Imagecreatetruecolor () two functions to create the specified canvas. The function of the two functions is consistent, is to create a specified size of the canvas, their prototype is as follows:

Copy Code code 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 can be accommodated is different. The Imagecreate () function can create an image based on a normal palette, which typically supports 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. You will need to use the handle of this resource type during the subsequent drawing process. For example, you can get the size of an image by calling Imagesx () and Imagesy () two functions. The code looks like this:
Copy Code code as follows:

<?php
$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 in use, be sure to destroy the resource, freeing memory and the image's storage unit. The process of destroying the canvas is very simple, and the Imagedestroy () function can be implemented. The syntax format looks like this:
Copy Code code as follows:

BOOL Imagedestroy (Resource $image)//Destroy an image

If the method call succeeds, the memory associated with the parameter $image is freed. Where the parameter $image is the image identifier returned by the image creation function.

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.