php中的绘图技术要点及应用总结
绘图属于php的高级部分,而且在实际的应用开发的过程中也是比较实用,在很多地方都可以看到技术的应用,如统计资料,折线,柱状等实时更新的图等,不可能通过纯美工的方法来实现,因为数据呈现着不可确定性,在一般的开发条件下,数据的获取是来自于服务器的,然而我们要根据这些数据进行友好的表示出来,即图形化的方式,在没有学习绘图技术之前是很难实现的,难度之处在于“变化”,所以,可以利用变量的方式来改变视图成为解决问题的首选方式,下面就是列举的一些php绘图的简单创建以及柱状图的制作过程:
一般的过程:
<?php $img_1=imagecreatetruecolor(400,300);//创键画布 $mycolor_1=imagecolorallocate($img_1, 255, 0, 0);//定义一个颜色(红色) $mycolor_2=imagecolorallocate($img_1, 232,222,13);//定义一个颜色(黄色) /*imageellipse($img_1, 150, 150, 50, 50, $mycolor_1);//定义绘的图的位置大小颜色(椭圆) imageline($img_1, 150, 0, 150, 175, $mycolor_1);//画一个直线,起始的坐标,颜色 imagerectangle($img_1, 125, 175, 175, 225, $mycolor_1);//画一个矩形 imagefilledrectangle($img_1, 125, 175, 175, 225, $mycolor_2);//画一个填充矩形 imagearc($img_1, 100, 100, 50, 50, 0, 30, $mycolor_2);//单位角度的弧 imagefilledarc($img_1, 50, 200, 100, 100, 30, 120, $mycolor_1,IMG_ARC_PIE);//一个扇形*/ $add_image=imagecreatefromgif("./file/01.gif");//加载原图片 $image_information=getimagesize("./file/01.gif");//获取图片的宽和高 imagecopy($img_1, $add_image, 0, 0, 0, 0, $image_information[0], $image_information[1]);//复制目标图片到画板 //imagestring($img_1, 5, 200, 200, "Hello徐宁", $mycolor_1);//写入字符,不建议,很弱 $str1="你好!!"; imagettftext($img_1, 10, 30, 200, 200, $mycolor_1, "./file/02.TTC", $str1);//可以去window/fonts去找。 header("Content-type: image/png");//定义返回数据类型 imagepng($img_1);//输出并保存图像 imagedestroy($img_1);//销毁服务器资源?>
下面是我测试制作柱状图的一份实例代码:
<?php //创建画布 $img_1=imagecreatetruecolor(500, 500); $white=imagecolorallocate($img_1, 255, 255, 255);//填充画布的背景色 imagefill($img_1, 0, 0, $white);//分别对应红蓝灰还有他们的暗色 $red=imagecolorallocate($img_1, 255,24,0); $darkred=imagecolorallocate($img_1, 146,12,0); $blue=imagecolorallocate($img_1, 11,6,139); $darkblue=imagecolorallocate($img_1, 5,5,52); $gary=imagecolorallocate($img_1, 193,193,193);//从低至上进行叠加全部为暗色 $darkgary=imagecolorallocate($img_1, 142,142,144); for($i=60; $i>=50; $i--){ imagefilledarc($img_1, 100, $i, 100, 50, 0, 35, $darkblue, IMG_ARC_PIE); imagefilledarc($img_1, 100, $i, 100, 50, 35, 75, $darkgary, IMG_ARC_PIE); imagefilledarc($img_1, 100, $i, 100, 50, 75, 360, $darkred, IMG_ARC_PIE); }//在最高层添加纯色层 imagefilledarc($img_1, 100, 50, 100, 50, 0, 35, $blue, IMG_ARC_PIE); imagefilledarc($img_1, 100, 50, 100, 50, 35, 75, $gary, IMG_ARC_PIE); imagefilledarc($img_1, 100, 50, 100, 50, 75, 360, $red, IMG_ARC_PIE);//定义,保存,显示,销毁 header("Content-type: image/png"); imagepng($img_1); imagedestroy($img_1);?>
上面还涉及到一些简单的算法,不是很难,但相对比较麻烦,但其对于数据的动态展现优势是显而易见的。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
