Home > Article > Backend Development > PHP code to draw a rectangle example code
This article mainly introduces the method of php to draw a rectangle, mainly involving the usage skills of the imagerectangle method in the GD library. Friends in need can refer to the following
The examples of this article describe php Method for drawing a rectangle. Share it with everyone for your reference. The specific implementation method is as follows:
The code is as follows:
<?php //1、创建画布 $im = imagecreatetruecolor(300,200);//新建一个真彩色图像,默认背景是黑色,返回图像标识符。另外还有一个函数 imagecreate 已经不推荐使用。 //2、绘制所需要的图像 $red = imagecolorallocate($im,255,0,0);//创建一个颜色,以供使用 imagerectangle($im,30,30,240,140,$red);//画一个矩形。参数说明:30,30表示矩形左上角坐标;240,140表示矩形右下角坐标;$red表示颜色 //imagefilledrectangle($im,30,30,240,140,$red);//填充的矩形 //3、输出图像 header("content-type: image/png"); imagepng($im);//输出到页面。如果有第二个参数[,$filename],则表示保存图像 //4、销毁图像,释放内存 imagedestroy($im); ?>
The above is the detailed content of PHP code to draw a rectangle example code. For more information, please follow other related articles on the PHP Chinese website!