Introduction to Imagecreate and Imagedestroy functions of PHP image processing

Source: Internet
Author: User
Tags image identifier
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!
  • 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.