PHP code to draw a rectangle example code

怪我咯
Release: 2023-03-12 20:02:01
Original
2711 people have browsed it

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);
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!