Create a canvas

Source: Internet
Author: User

In the development of Web projects, the picture is an indispensable part of the foreground page, the traditional way to add a picture in the page is generally through the HTML language tags to achieve, in the PHP language in order to improve the transmission rate of the page, to facilitate data statistics, Sometimes the GD2 function library or Jpgraph class library is drawn manually by the programmer.


Create a canvasThe GD2 function library is very powerful in graphic image rendering, where developers can draw on the basis of existing images or draw on the basis of no footage, in which case the canvas is created first, and all subsequent operations will be based on the canvas created. Creating a canvas in the GD2 function library is implemented by the Imagecreate () function. The syntax is as follows:Resource  imagecreate (  int $width  ,  int $height  )
The function returns an identifier for an image, the parameter $width, $height represented as the size of the image, in pixels.
For example: Apply the Imagecreate () function to create a canvas with a width of 500px, a height of 300px, and set the canvas Beijing color RGB value to (211 126 29), and finally output a GIF format image, the code is as follows:
<?php    Header ("Content-type:image/gif");//The page is output in GIF format, or the picture is not displayed properly    $im = Imagecreate (500,300);//Create a 500* 300 Canvas    $white = imagecolorallocate ($im, 211,126,29);//Set canvas background color    imagegif ($IM);//output image in GIF format

The result of the operation is:


Create a canvas

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.