首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> PHP 程式設計 >> PHP 綜合知識

PHP GD 庫函數完整參考手冊

     編輯:PHP 綜合知識

PHP GD 庫提供了強大的圖像處理能力,本文整理了常用 GD 函數的用法與參數說明,供開發者快速查閱。

圖像信息獲取

函數功能語法
GetImageSize獲取圖片尺寸(寬、高)array GetImageSize(string filename, array &imageinfo)

繪圖基礎函數

函數功能語法
ImageCreate創建新的基於調色板的圖像resource ImageCreate(int x_size, int y_size)
ImageCreateTrueColor創建真彩色圖像resource ImageCreateTrueColor(int x_size, int y_size)
ImageDestroy銷毀圖像釋放內存bool ImageDestroy(resource im)

顏色處理

函數功能語法
ImageColorAllocate分配顏色int ImageColorAllocate(resource im, int red, int green, int blue)
ImageColorTransparent設置透明色int ImageColorTransparent(resource im, int col)

幾何圖形繪製

函數功能語法
ImageArc繪製橢圓弧bool ImageArc(resource im, int cx, int cy, int w, int h, int s, int e, int col)
ImageLine繪製直線bool ImageLine(resource im, int x1, int y1, int x2, int y2, int col)
ImageDashedLine繪製虛線bool ImageDashedLine(resource im, int x1, int y1, int x2, int y2, int col)
ImageRectangle繪製矩形框bool ImageRectangle(resource im, int x1, int y1, int x2, int y2, int col)
ImageFilledRectangle繪製填充矩形bool ImageFilledRectangle(resource im, int x1, int y1, int x2, int y2, int col)
ImagePolygon繪製多邊形bool ImagePolygon(resource im, array points, int num_points, int col)
ImageFilledPolygon繪製填充多邊形bool ImageFilledPolygon(resource im, array points, int num_points, int col)
ImageEllipse繪製橢圓bool ImageEllipse(resource im, int cx, int cy, int w, int h, int col)
ImageFill區域填充bool ImageFill(resource im, int x, int y, int col)
ImageFillToBorder邊界填充bool ImageFillToBorder(resource im, int x, int y, int border, int col)
ImageSetPixel繪製單個像素bool ImageSetPixel(resource im, int x, int y, int col)

文字繪製

函數功能語法
ImageChar水平繪製單字符bool ImageChar(resource im, int font, int x, int y, string c, int col)
ImageCharUp垂直繪製單字符bool ImageCharUp(resource im, int font, int x, int y, string c, int col)
ImageString水平繪製字符串bool ImageString(resource im, int font, int x, int y, string s, int col)
ImageStringUp垂直繪製字符串bool ImageStringUp(resource im, int font, int x, int y, string s, int col)
ImageTTFText使用 TrueType 字體繪製文字array ImageTTFText(resource im, int size, int angle, int x, int y, int col, string fontfile, string text)
ImageFontWidth獲取字體寬度int ImageFontWidth(int font)
ImageFontHeight獲取字體高度int ImageFontHeight(int font)
ImageLoadFont加載點陣字體int ImageLoadFont(string file)

圖像複製與縮放

函數功能語法
ImageCopyResized複製並調整大小(低質量)bool ImageCopyResized(resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
ImageCopyResampled複製並重採樣(高質量)bool ImageCopyResampled(resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
ImageCopy直接複製圖像區域bool ImageCopy(resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int srcW, int srcH)

輸出與交錯

函數功能語法
ImageJPEG輸出 JPEG 格式bool ImageJPEG(resource im, string filename, int quality)
ImagePNG輸出 PNG 格式bool ImagePNG(resource im, string filename, int quality, int filters)
ImageGIF輸出 GIF 格式bool ImageGIF(resource im, string filename)
ImageInterlace啟用/禁用交錯顯示int ImageInterlace(resource im, int interlace)

進階功能提示

  • GD 2.0+ 版本建議使用 ImageCreateTrueColor 替代 ImageCreate 以獲得真彩色支持
  • 文字繪製推薦使用 ImageTTFText 配合 TTF 字體文件,支持中文等多語言
  • 圖像縮放優先使用 ImageCopyResampled 獲得更好質量
  • 所有圖像資源使用完畢必須調用 ImageDestroy 釋放內存
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved