本文章免費提供一款php圖片處理類:縮略,裁剪,圓角,傾斜代碼,他可以切出不同風格的圖片哦,哈哈,比其它的在線切圖要好很多了哦。
php教程圖片處理類:縮略,裁剪,圓角,傾斜
class resizeimage
{
//圖片類型
var $type;
//實際寬度
var $width;
//實際高度
var $height;
//改變後的寬度
var $resize_width;
//改變後的高度
var $resize_height;
//是否裁圖
var $cut;
//源圖象
var $srcimg;
//目標圖象地址
var $dstimg;
//圓角源
var $corner;
var $im;
function resizeimage($img, $corner, $wid, $hei,$c, $corner_radius, $angle)
{
$this->srcimg = $img;
$this->corner = $corner;
$this->resize_width = $wid;
$this->resize_height = $hei;
$this->cut = $c;
$this->corner_radius = $corner_radius;
$this->angle = $angle;
//圖片的類型
$this->type = substr(strrchr($this->srcimg,"."),1);
//初始化圖象
$this->initi_img();
//目標圖象地址
$this -> dst_img();
//--
$this->width = imagesx($this->im);
$this->height = imagesy($this->im);
//生成圖象
$this->newimg();
imagedestroy ($this->im);
}
function newimg()
{
//改變後的圖象的比例
$resize_ratio = ($this->resize_width)/($this->resize_height);
//實際圖象的比例
$ratio = ($this->width)/($this->height);
if(($this->cut)=="1")
//裁圖
{
if($ratio>=$resize_ratio)
//高度優先
{
$newimg = imagecreatetruecolor($this->resize_width,$this->resize_height);
imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width,$this->resize_height, (($this->height)*$resize_ratio), $this->height);
$tmp = $this->rounded_corner($newimg,$this->resize_width);
imagepng ($tmp,$this->dstimg);
}
if($ratio<$resize_ratio)
//寬度優先
{
$newimg = imagecreatetruecolor($this->resize_width,$this->resize_height);
imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->width, (($this->width)/$resize_ratio));
$tmp = $this->rounded_corner($newimg);
imagepng ($tmp,$this->dstimg);
}
}
else
1 2 3