This article mainly introduces the php Method for drawing a rectangle, which mainly involves the use of imagerectangle In the GD library. For more information, see
This article mainly introduces the php Method for drawing a rectangle, which mainly involves the use of imagerectangle In the GD library. For more information, see
This example describes how to draw a rectangle in php. Share it with you for your reference. The specific implementation method is as follows:
The Code is as follows:
<? Php
// 1. Create a canvas
$ Im = imagecreatetruecolor (300,200); // create a real-color image. The default background is black and the image identifier is returned. Another function, imagecreate, is not recommended.
// 2. Draw the desired image
$ Red = imagecolorallocate ($ im, 255, 0, 0); // create a color for use
Imagerectangle ($ im, 30,30, 240,140, $ red); // draw a rectangle. Parameter description: 30, 30 indicates the coordinate of the upper left corner of the rectangle; 240,140 indicates the coordinate of the lower right corner of the rectangle; $ red indicates the color.
// Imagefilledrectangle ($ im, 30, 30, 240,140, $ red); // filled rectangle
// 3. output image
Header ("content-type: image/png ");
Imagepng ($ im); // output to the page. If the second parameter [, $ filename] exists, the image is saved.
// 4. Destroy images and release memory
Imagedestroy ($ im );
?>
I hope this article will help you with php programming.
,