《PHP編程:php使用gd2繪制基本圖形示例(直線、圓、正方形)》要點:
本文介紹了PHP編程:php使用gd2繪制基本圖形示例(直線、圓、正方形),希望對您有用。如果有疑問,可以聯系我們。
PHP編程本文實例講述了php使用gd2繪制基本圖形.分享給大家供大家參考,具體如下:
PHP編程應用GD2函數可以繪制的圖形有多種,最基本的圖形包括條、圓、方形等.無論開發人員繪制多么復雜的圖形,都是在這些最基本的圖形的基礎上進行深化的,只有掌握了最基本的圖形的繪制方法,才能繪制出各種具有獨特風格的圖形.
PHP編程在GD2中可以分別應用imageline()函數、imagearc()函數和imagerectangle()函數繪制直線,圓形和方法.
PHP編程下面將介紹這些函數的使用方法:
PHP編程bool imageline( resource image, int x1, int y1, int x2, int y2, int color )
PHP編程imageline()函數用color顏色在圖像image中從坐標(x1,y1)到(x2,y2)(圖像左上角為(0,0))繪制一條線段.
PHP編程bool imagearc( resource image, int cx, int cy, int w, int h, int s, int e, int color)
PHP編程image : 表示圖像的handle
cx,cy 原點坐標(0,0)為圖片的左上角,參數cx,cy為橢圓圓心坐標
w,h分別為水平軸長和垂直軸長
s,e分別為起始角與結束角
color為弧線的顏色
PHP編程bool imagerectangle( resource image, int x1, int y1, int x2, int y2, int color)
PHP編程imagerectangle()函數以color顏色在image圖像中繪制一個矩形,其左上角坐標為( x1,y1),右下角坐標為( x2, y2).圖像的左上角坐標為(0,0)
PHP編程例如應用以上函數,分別繪制直線、正圓和正方形,并且以白色作為線條的基色,代碼如下
PHP編程
<?php
header("Content-type: image/png");//將圖像輸出到瀏覽器
$img = imagecreate(560, 200);//創建一個560X200像素的圖像
$bg = imagecolorallocate($img, 0, 0, 255);//設置圖像的背景顏色
$white = imagecolorallocate($img, 255, 255, 255);//設置繪制圖像的線的顏色
imageline($img, 20, 20, 150, 180, $white);//繪制一條線
imagearc($img, 250, 100, 150, 150, 0, 360, $white);//繪制一個圓
imagerectangle($img, 350, 20, 500, 170, $white);//繪制一個正方形
imagepng($img);//以PNG格式輸出圖像
imagedestroy($img);//釋放資源
PHP編程運行結果如下:
PHP編程
PHP編程更多關于PHP相關內容感興趣的讀者可查看本站專題:《PHP圖形與圖片操作技巧匯總》、《PHP基本語法入門教程》、《php面向對象程序設計入門教程》、《PHP網絡編程技巧總結》、《PHP數組(Array)操作技巧大全》、《php字符串(string)用法總結》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》
PHP編程希望本文所述對大家PHP程序設計有所幫助.
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/1790.html