This article mainly introduces the method of drawing a circle in PHP, and analyzes in detail the basic steps of drawing graphics in PHP and the implementation method of drawing a circle. Friends in need can refer to it
The examples in this article describe PHP How to draw a circle. Share it with everyone for your reference. The specific implementation method is as follows:
phpBasic steps for drawing, there are four steps (the extension = php_gb2.dll component in php.ini needs to be enabled first)
1. Create a canvas;
2. Draw the required image (circle, straight line, rectangle, sector, arc...);
3 , output to the web page, or save as another;
4. Destroy the image (the purpose is to release the memory occupied by the image).
The three most commonly used image formats for website development: gif, jpg/jpeg, png
(1) Gif format: has the highest compression rate, but can only display 256 colors, which may cause color distortion lost. Advantages: Possibility to display animated images.
(2) jpg/jpeg format: The compression rate is also relatively high (lossy compression will also lose some colors), and it is often used on web pages.
(3) png format: It combines the advantages of gif and jpg, but it cannot display animated images. High fidelity, supports lossless compression, has the best color preservation, and is relatively larger than jpg/jpeg.
php draws a circle, the code is as follows:
The code is as follows:
<?php //1、创建画布 $im = imagecreatetruecolor(300,200);//新建一个真彩色图像,默认背景是黑色,返回图像标识符。另外还有一个函数 imagecreate 已经不推荐使用。 //2、绘制所需要的图像 $red = imagecolorallocate($im,255,0,0);//创建一个颜色,以供使用 imageellipse($im,30,30,40,40,$red);//画一个圆。参数说明:30,30为圆形的中心坐标;40,40为宽和高,不一样时为椭圆;$red为圆形的颜色(框颜色) //3、输出图像 header("content-type: image/png"); imagepng($im);//输出到页面。如果有第二个参数[,$filename],则表示保存图像 //4、销毁图像,释放内存 imagedestroy($im); ?>
The above is the detailed content of How to draw a circle in php?. For more information, please follow other related articles on the PHP Chinese website!