一、創建圖片資源
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();
四、圖片的裁剪
imagecopyresized()
imagecopyresampled();
五、加水印(文字、圖片)
字符串編碼轉換string iconv ( string $in_charset , string $out_charset , string $str )
六、圖片旋轉
imagerotate();//制定角度的圖片翻轉
七、圖片的翻轉
沿X軸 沿Y軸翻轉
八、銳化
imagecolorsforindex()
imagecolorat()
在圖片上畫圖形 $img=imagecreatefromgif("./images/map.gif");
<? = imagecolorallocate(, 255, 0, 0 imageline(, 0, 0, 100, 100, imageellipse(, 200, 100, 100, 100, imagegif(, "./images/map2.gif" imagedestroy( 復制代碼 代碼如下: ="./images/hee.jpg" =0.3 (, )=( =* =* =imagecreatetruecolor(, =imagecreatefromjpeg( imagecopyresized(, ,0, 0,0, 0,, , , imagejpeg(, "./images/hee2.jpg" imagedestroy( imagedestroy( 復制代碼 代碼如下: thumn(, , , (, )=(); ( && ( < = ( / ) * } = ( / ) * =imagecreatetruecolor(, =imagecreatefromjpeg( imagecopyresampled(, , 0, 0, 0, 0, , , , imagejpeg(, imagedestroy( imagedestroy( thumn("images/hee.jpg", 200, 200, "./images/hee3.jpg" 復制代碼 代碼如下: thumn(, , , (, )=( ( && ( < = ( / ) * } = ( / ) * =imagecreatetruecolor(, =imagecreatefromgif( =imagecolortransparent( ( >=0 && < imagecolorstotal()){ =imagecolorsforindex(, ); =imagecolorallocate(, ["red"], ["green"], ["blue" imagefill(, 0, 0, imagecolortransparent(, imagecopyresized(, , 0, 0, 0, 0, , , , imagegif(, imagedestroy( imagedestroy( thumn("images/map.gif", 200, 200, "./images/map3.gif");
<? cut(, , , , , =imagecreatefromjpeg(=imagecreatetruecolor(, , , 0, 0, , , , ,,, "./images/hee.jpg", 440, 140, 117, 112, "./images/hee5.jpg"?>
文字水印
<? mark_text(, , , =imagecreatefromjpeg( =imagecolorallocate(, 0, 255, 0 imagettftext(, 20, 0, , , , "simkai.ttf", imagejpeg(, "./images/hee7.jpg" imagedestroy( mark_text("./images/hee.jpg", "細說PHP", 150, 250 mark_pic(, , , =imagecreatefromjpeg( =imagecreatefromgif( =imagesx( =imagesy( imagecopy(, , , , 0, 0, , imagejpeg(,"./images/hee8.jpg" imagedestroy( imagedestroy( mark_pic("./images/hee.jpg", "./images/gaolf.gif", 50, 200);
圖片旋轉
<? =imagecreatefromjpeg("./images/hee.jpg" =imagerotate(, 45, 0 imagejpeg(, "./images/hee9.jpg" ?>
<? turn_y(, =imagecreatefromjpeg( =imagesx( =imagesy( =imagecreatetruecolor(, (=0; < ; ++ imagecopy(, , --1, 0, , 0, 1, imagejpeg(, imagedestroy( imagedestroy( turn_x(, =imagecreatefromjpeg( =imagesx( =imagesy( =imagecreatetruecolor(, (=0; < ; ++ imagecopy(, ,0, --1, 0, , , 1 imagejpeg(, imagedestroy( imagedestroy( turn_y("./images/hee.jpg", "./images/hee11.jpg" turn_x("./images/hee.jpg", "./images/hee12.jpg" ?>