『壹』 php圖像處理函數有哪些
php圖像處理函數大全
php圖片處理代碼分享,包括縮放、剪裁、縮放、翻轉、旋轉、透明、銳化等。需要的朋友可以參考下
一、創建圖片資源
imagecreatetruecolor(width,height);
imagecreatefromgif(圖片名稱);
imagecreatefrompng(圖片名稱);
imagecreatefromjpeg(圖片名稱);畫出各種圖像
imagegif(圖片資源,保存路徑);
imagepng()
imagejpeg();
二、獲取圖片屬性
imagesx(res//寬度
imagesy(res//高度
getimagesize(文件路徑)
返回一個具有四個單元的數組。索引
0 包含圖像寬度的像素值,索引 1 包含圖像高度的像素值。索引 2 是圖像類型的標記:1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 =
PSD,6 = BMP,7 = TIFF(intel byte order),8 = TIFF(motorola byte order),9 = JPC,10
= JP2,11 = JPX,12 = JB2,13 = SWC,14 = IFF,15 = WBMP,16 = XBM。這些標記與 PHP 4.3.0 新加的
IMAGETYPE 常量對應。索引 3 是文本字元串,內容為「height="yyy" width="xxx"」,可直接用於 IMG
標記。
銷毀圖像資源
imagedestroy(圖片資源);
三、透明處理
PNG、jpeg透明色都正常,只有gif不正常
imagecolortransparent(resource
image [,int
color])//將某個顏色設置成透明色
imagecolorstotal()
imagecolorforindex();
四、圖片的裁剪
imageresized()
imageresampled();
五、加水印(文字、圖片)
字元串編碼轉換string iconv ( string $in_charset ,
string $out_charset , string $str )
六、圖片旋轉
imagerotate();//制定角度的圖片翻轉
七、圖片的翻轉
沿X軸 沿Y軸翻轉
八、銳化
imagecolorsforindex()
imagecolorat()