Php image operations class (1/3) _ PHP Tutorial

Source: Internet
Author: User
Php image Operation class (13 ). Php image operations this program can obtain the image size, format, and other information. It can also process the image thumbnails and add watermarks to the image. Php Tutorial Image operation Class php image Operation class this program can get the image size, format and other information, at the same time, you can also process the image thumbnails and add watermarks to the image.

Php Tutorial Image operations
This program can obtain the image size, format, and other information, as well as thumbnails and watermarks for the image.

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

// Construct
Public function _ construct ($ filename ){
$ This-> filename = $ filename;
$ This-> info = @ getimagesize ($ filename );
If ($ this-> info [2]> 3) {echo "only supports gif, jpeg, and 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); // reversed
$ OK = true;
Break;
Case 2:
Imagefilter ($ this-> im, img_filter_grayscale); // Black/White
$ OK = true;
Break;
Case 3:
Imagefilter ($ this-> im, img_filter_emboss); // embossed
$ 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 a file
Imagedestroy ($ this-> im );
Return 1;
} Else {
Imagedestroy ($ this-> im );
Return 0 ;}
}

1 2 3

You can use this program to obtain the image size, format, and other information, as well as thumbnails and watermarks. Php Tutorial Image operations...

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.