PHP繪圖


繪圖
創建一個畫布:imagecreatetruecolor(寬,高),默認黑色

顯示圖像:header("content-type:image/圖片格式類型");

* 圖片格式類型:gif(動圖)\jpg(jpeg)-網站用的最普遍,大小較小,色彩較多\png-色彩還原度最好,較大

圖像顯示:
imagejpeg($img);//$img-資源類型
imagegif($img);
imagepng($img);
保存圖像:imagejpeg($img,"圖片路徑(含圖片名字)");
既要顯示又要保存:
imagepng($img);//顯示
imagepng($img,"img/2.png");//保存

定義顏色:
$red = imagecolorallocate(圖片資源,RGB-紅色,RGB-綠,RGB-藍);

畫點:
imagesetpixel(圖片資源,x坐標,y坐標,顏色);

畫線:兩個點坐標
imageline(圖片資源,x1坐標,y1坐標,x2,y2,顏色);

畫虛線:
1)樣式的數組設置
$style = array(//5個像素的黃色 6個像素的藍色
$yellow,$yellow,$yellow,$yellow,$yellow,$yellow,
$blue,$blue,$blue,$blue,$blue,$blue
);
2)imagesetstyle(圖片資源,$style);
3)畫線:imageline($img,10,10,100,100,IMG_COLOR_STYLED);

矩形:
imagerectangle(圖片資源,起點x,起點y,終點x,終點y,顏色); 起點\終點 組成的是一條對角線
imagefilledrectangle(圖片資源,起點x,起點y,終點x,終點y,顏色) 圖形顏色填充

圓形:
imageellipse(圖片資源,圓心x,圓心y,寬度,高度,顏色);
imagefilledellipse(圖片資源,圓心x,圓心y,寬度,高度,顏色) 圖形顏色填充

弧線:
imagearc(圖片資源,圓心x,圓心y,寬,高,起點度數,終點度數,顏色);

多邊形
imagepolygon();
imagefilledpolygon($img,
array(//頂點坐標數組(按順序)
10,0,
50,20,
100,90,
120,50,
30,60
),
5,//頂點個數
顏色
);

畫字符串:
imagestring(圖片資源,字體(1-5),坐標x,坐標y,"字符串",顏色)
* 不能打印中文

imagettftext(圖片資源,字號,角度,坐標x,坐標y,顏色,"字體文件路徑(含文件名)","字符串(可以打印中文)");


===========================================
常用顏色:
$red = imagecolorallocate($img,255,0,0);
$green= imagecolorallocate($img,0,255,0);
$blue = imagecolorallocate($img,0,0,255);
$white = imagecolorallocate($img,255,255,255);
$black = imagecolorallocate($img,0,0,0);
$yellow = imagecolorallocate($img,255,255,0);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM