The example in this article describes how PHP draws a rectangle. Share to everyone for your reference. The implementation methods are as follows:
Copy Code code as follows:
<?php
1. Create Canvas
$im = Imagecreatetruecolor (300,200);//Create a new true color image, the default background is black, and return the image identifier. Another function, imagecreate, is deprecated.
2, to draw the desired image
$red = Imagecolorallocate ($im, 255,0,0);//Create a color to use
Imagerectangle ($im, 30,30,240,140, $red);//Draw a rectangle. Parameter Description: 30,30 represents the upper-left corner coordinates of the rectangle, 240,140 represents the rectangle's lower-right corner coordinate, and $red represents the color
Imagefilledrectangle ($im, 30,30,240,140, $red);/Filled Rectangle
3. Output image
Header ("Content-type:image/png");
Imagepng ($im);//output to page. If there is a second argument [, $filename], the image is saved
4, destroy the image, free memory
Imagedestroy ($im);
?>
I hope this article will help you with your PHP program design.