Home > php教程 > php手册 > php图像操作类(1/3)

php图像操作类(1/3)

WBOY
Release: 2016-06-13 09:48:19
Original
969 people have browsed it

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template