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...