Home > Backend Development > PHP Tutorial > PHP image manipulation class (1/3)_PHP tutorial

PHP image manipulation class (1/3)_PHP tutorial

WBOY
Release: 2016-07-13 10:45:17
Original
757 people have browsed it

php image manipulation class This program can obtain image size, format and other information, and can also perform thumbnail processing and add watermarks to images.

php tutorial image manipulation class
This program can obtain image size, format and other information, and can also perform thumbnail processing on images and add watermarks to images.

class image{
         public $filename;
        private $info;
        private $im;

//Construction
         public function __construct($filename){
$this->filename = $filename;
$this->info = @getimagesize($filename);
If($this->info[2]>3){echo "Only supports gif, jpeg, png formats.";exit;}

}
         
//Load
         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;
}
}

// Save
         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;
}
                                                

//Filter
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);//Invert color
$ok=true;
Break;
case 2:
Imagefilter($this->im,img_filter_grayscale); //Black and white
$ok=true;
Break;
case 3:
Imagefilter($this->im,img_filter_emboss);//Emboss
$ok=true;
Break;
case 4:
Imagefilter($this->im,img_filter_gaussian_blur); //Gaussian blur
$ok=true;
Break;
case 5:
Imagefilter($this->im,img_filter_brightness,50); //Brightness 50
$ok=true;
Break;
case 6:
Imagefilter($this->im,img_filter_contrast,-50); //Contrast-50
$ok=true;
break;
}
if($ok){
$this->imagesave($this->im,$savename,$this->info[2]); //Write file
Imagedestroy($this->im);
Return 1;
}else{
Imagedestroy($this->im);
Return 0;}
}

1 2 3

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633038.htmlTechArticlephp image operation class This program can obtain image size, format and other information, and can also thumbnail the image. Process and add watermarks to images. PHP tutorial image manipulation class...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template