php圖像操作類 本款程序可以獲取圖片大小,格式等信息,同時還可以對圖片進行縮略圖處理與給圖片加水印功能哦。
php教程圖像操作類
本款程序可以獲取圖片大小,格式等信息,同時還可以對圖片進行縮略圖處理與給圖片加水印功能哦。
class image{
public $filename;
private $info;
private $im;
//構造
public function __construct($filename){
$this->filename = $filename;
$this->info = @getimagesize($filename);
if($this->info[2]>3){echo "只支持gif、jpeg、png 格式。";exit;}
}
// 載入
public function imgload(){
switch($this->info[2]){
case 1:
$this->im=@imagecreatefromgif($this->filename);
break;
case 2:
$this->im=@imagecreatefromjpeg($this->filename);
break;
case 3:
$this->im=@imagecreatefrompng($this->filename);
break;
}
}// 保存
public function imagesave($img,$savename,$inf){
switch($inf){
case 1:
imagegif($img,$savename);;
break;
case 2:
imagejpeg($img,$savename);;
break;
case 3:
imagepng($img,$savename);;
break;
}
}
//濾鏡
public function filter($arg=1,$savename=''){
$this->imgload();
if($savename=='')$savename='f_'.$this->filename;
$ok=false;
switch($arg){
case 1:
imagefilter($this->im,img_filter_negate);//反色
$ok=true;
break;
case 2:
imagefilter($this->im,img_filter_grayscale); //黑白
$ok=true;
break;
case 3:
imagefilter($this->im,img_filter_emboss);//浮雕
$ok=true;
break;
case 4:
imagefilter($this->im,img_filter_gaussian_blur); //高斯模糊
$ok=true;
break;
case 5:
imagefilter($this->im,img_filter_brightness,50); //亮度50
$ok=true;
break;
case 6:
imagefilter($this->im,img_filter_contrast,-50); //對比度-50
$ok=true;
break;
}
if($ok){
$this->imagesave($this->im,$savename,$this->info[2]); //寫文件
imagedestroy($this->im);
return 1;
}else{
imagedestroy($this->im);
return 0;}
}
1 2 3