一
imagecreatetruecolor(width
imagecreatefromgif(圖片名稱);
imagecreatefrompng(圖片名稱);
imagecreatefromjpeg(圖片名稱);畫出各種圖像 imagegif(圖片資源
imagepng()
imagejpeg();
二
imagesx(res//寬度
imagesy(res//高度
getimagesize(文件路徑)
返回一個具有四個單 元的數組
銷毀圖像資源
imagedestroy(圖片資源);
三
PNG
imagecolortransparent(resource image [
imagecolorstotal()
imagecolorforindex();
四
imagecopyresized()
imagecopyresampled();
五
字符串編碼轉換string iconv ( string $in_charset
六
imagerotate();//制定角度的圖片翻轉
七
沿X軸 沿Y軸翻轉
八
imagecolorsforindex()
imagecolorat()
在圖片上畫圖形 $img=imagecreatefromgif("
$red= imagecolorallocate($img
imageline($img
imageellipse($img
imagegif($img
imagedestroy($img);
圖片普通縮放
復制代碼 代碼如下:$filename="
$per=
list($width
$n_w=$width*$per;
$n_h=$width*$per;
$new=imagecreatetruecolor($n_w
$img=imagecreatefromjpeg($filename);
//拷貝部分圖像並調整
imagecopyresized($new
//圖像輸出新圖片
imagejpeg($new
imagedestroy($new);
imagedestroy($img);
圖片等比例縮放
function thumn($background
list($s_w
if ($width && ($s_w < $s_h)) {
$width = ($height / $s_h) * $s_w;
} else {
$height = ($width / $s_w) * $s_h;
}
$new=imagecreatetruecolor($width
$img=imagecreatefromjpeg($background);
imagecopyresampled($new
imagejpeg($new
imagedestroy($new);
imagedestroy($img);
}
thumn("images/hee
gif透明色處理
function thumn($background
list($s_w
if ($width && ($s_w < $s_h)) {
$width = ($height / $s_h) * $s_w;
} else {
$height = ($width / $s_w) * $s_h;
}
$new=imagecreatetruecolor($width
$img=imagecreatefromgif($background);
$otsc=imagecolortransparent($img);
if($otsc >=
$tran=imagecolorsforindex($img
$newt=imagecolorallocate($new
imagefill($new
imagecolortransparent($new
}
imagecopyresized($new
imagegif($new
imagedestroy($new);
imagedestroy($img);
}
thumn("images/map
圖片裁剪
function cut($background
$back=imagecreatefromjpeg($background);
$new=imagecreatetruecolor($cut_width
imagecopyresampled($new
imagejpeg($new
imagedestroy($new);
imagedestroy($back);
}
cut("
圖片加水印
文字水印
復制代碼 代碼如下:function mark_text($background
$back=imagecreatefromjpeg($background);
$color=imagecolorallocate($back
imagettftext($back
imagejpeg($back
imagedestroy($back);
}
mark_text("
//圖片水印
function mark_pic($background
$back=imagecreatefromjpeg($background);
$water=imagecreatefromgif($waterpic);
$w_w=imagesx($water);
$w_h=imagesy($water);
imagecopy($back
imagejpeg($back
imagedestroy($back);
imagedestroy($water);
}
mark_pic("
圖片旋轉
復制代碼 代碼如下:$back=imagecreatefromjpeg("
$new=imagerotate($back
imagejpeg($new
圖片水平翻轉垂直翻轉
function turn_y($background
$back=imagecreatefromjpeg($background);
$width=imagesx($back);
$height=imagesy($back);
$new=imagecreatetruecolor($width
for($x=
imagecopy($new
}
imagejpeg($new
imagedestroy($back);
imagedestroy($new);
}
function turn_x($background
$back=imagecreatefromjpeg($background);
$width=imagesx($back);
$height=imagesy($back);
$new=imagecreatetruecolor($width
for($y=
imagecopy($new
}
imagejpeg($new
imagedestroy($back);
imagedestroy($new);
}
turn_y("
turn_x("
圖片銳化
function sharp($background
$back=imagecreatefromjpeg($background);
$b_x=imagesx($back);
$b_y=imagesy($back);
$dst=imagecreatefromjpeg($background);
for($i=
for($j=
$b_clr
$b_clr
$r=intval($b_clr
$g=intval($b_clr
$b=intval($b_clr
$r=min(
$g=min(
$b=min(
if(($d_clr=imagecolorexact($dst
$d_clr=Imagecolorallocate($dst
}
imagesetpixel($dst
}
}
imagejpeg($dst
imagedestroy($back);
imagedestroy($dst);
}
sharp("
From:http://tw.wingwit.com/Article/program/PHP/201311/21300.html