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);?>
登入後複製
上面还涉及到一些简单的算法,不是很难,但相对比较麻烦,但其对于数据的动态展现优势是显而易见的。
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前
By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
擊敗分裂小說需要多長時間?
3 週前
By DDD
R.E.P.O.保存文件位置:在哪里以及如何保護它?
3 週前
By DDD

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)