search
Homephp教程php手册php图像操作类(1/3)

php图像操作类(1/3)

Jun 13, 2016 am 09:48 AM
phpCanimagepicturesizeoperateFormatprogramkindObtainconduct

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

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor