1. 程式人生 > >GD庫常用函式

GD庫常用函式

//開啟GD庫 在php.ini中去掉extension=php_gd2.dll前的‘;’號
step1:建立畫布

            imagecreate 新建一個基於調色盤的影象
            imagecreatetruecolor 新建一個真彩色影象
            imagecreatefromjpeg 由檔案或 URL 建立一個新圖象。
            imagecreatefrompng 由檔案或 URL 建立一個新圖象。

step2:準備顏色

            imagecolorallocate 為一幅影象分配顏色

step3:填充背景

            imagefill 區域填充

step4:作畫

            imagesetpixel 畫點
            imageline 畫一條線段
            imagerectangle 畫一個矩形
            imagefilledrectangle 畫一矩形並填充
            imagepolygon 畫一個多邊形
            imagefilledpolygon 畫一多邊形並填充
            imageellipse 畫一個橢圓
            imagefilledellipse 畫一橢圓並填充
            imagearc 畫橢圓弧
            imagefilledarc 畫一橢圓弧且填充
            imagettftext 用 TrueType 字型向影象寫入文字 (新增文字水印)
            imagecopy 拷貝影象的一部分
            imagecopymerge 拷貝併合並影象的一部分(新增圖片水印)
            imagecopyresampled 重取樣拷貝部分影象並調整大小(縮放、剪裁圖片)
            getimagesize 取得影象大小

step5:儲存,輸出

           imagepng 以 PNG 格式將影象輸出到瀏覽器或檔案
           imagejpeg 輸出圖象到瀏覽器或檔案

tep6:關閉銷燬資源(釋放記憶體)

           imagedestroy 銷燬一影象