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