PHP Image Manipulation Class (1/3) _php Tutorial

Source: Internet
Author: User
PHP Image Operation class This program can obtain the image size, format and other information, but also to the image of the thumbnail processing and image watermark function Oh.

PHP Tutorial Image Manipulation Class
This section of the program can obtain image size, format and other information, but also to image thumbnail processing and to the image watermark function Oh.

Class image{
public $filename;
Private $info;
Private $im;

Structure
Public function __construct ($filename) {
$this->filename = $filename;
$this->info = @getimagesize ($filename);
if ($this->info[2]>3) {echo] only supports GIF, JPEG, PNG format. "; exit;}

}

Gta5-In
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);//Inverse color
$ok =true;
Break
Case 2:
ImageFilter ($this->im,img_filter_grayscale); Black
$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 Ratio-50
$ok =true;
Break
}
if ($ok) {
$this->imagesave ($this->im, $savename, $this->info[2]); Write a file
Imagedestroy ($this->im);
return 1;
}else{
Imagedestroy ($this->im);
return 0;}
}

1 2 3

http://www.bkjia.com/PHPjc/633038.html www.bkjia.com true http://www.bkjia.com/PHPjc/633038.html techarticle PHP Image Operation class This program can obtain the image size, format and other information, but also to the image of the thumbnail processing and image watermark function Oh. PHP Tutorial image Operation Class ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.