首先得確定php.ini設置有沒有打開GD擴展功能,測試如下
print_r(gd_info());
Array ( [GD Version] => bundled (2.0.34 compatible) [FreeType Support] => 1 [FreeType Linkage] => with freetype [T1Lib Support] => 1 [GIF Read Support] => 1 [GIF Create Support] => 1 [JPG Support] => 1 [PNG Support] => 1 [WBMP Support] => 1 [XPM Support] => [XBM Support] => 1 [JIS-mapped Japanese Font Support] => )
GD畫圖一般步驟如下:
1.創建一張畫布資源
2.創建顏色畫筆
3.畫圖
4.保存圖片或輸出圖片
5.銷毀內存畫布資源
測試代碼如下:
注:GD庫強大的可以畫各種報表(如柱狀圖,餅狀圖等)、縮略圖、加水印圖和股票走勢圖