<?php/** * desription judge whether gif animation * @param sting $image _file Picture Path * @return Boolean t is f/function
Check_gifcartoon ($image _file) {$fp = fopen ($image _file, ' RB ');
$image _head = fread ($fp, 1024);
Fclose ($FP); Return Preg_match ("/") Chr (0x21). chr (0xff). chr (0x0b). ' NETSCAPE2.0 '. '
/", $image _head)? false:true; /** * desription Compressed picture * @param sting $imgsrc Picture path * @param string $IMGDST Compressed save path/function Compressed_im
Age ($IMGSRC, $IMGDST) {list ($width, $height, $type) =getimagesize ($IMGSRC);
$new _width = ($width >600?600: $width) *0.9;
$new _height = ($height >600?600: $height) *0.9;
Switch ($type) {Case 1: $giftype =check_gifcartoon ($IMGSRC);
if ($giftype) {header (' content-type:image/gif ');
$image _wp=imagecreatetruecolor ($new _width, $new _height);
$image = Imagecreatefromgif ($IMGSRC);
Imagecopyresampled ($image _wp, $image, 0, 0, 0, 0, $new _width, $new _height, $width, $height); 75 represents the quality, compressed picture capacity size imagejpeg ($image _wp, $IMGDST, 75);
Imagedestroy ($image _wp);
} break;
Case 2:header (' content-type:image/jpeg ');
$image _wp=imagecreatetruecolor ($new _width, $new _height);
$image = Imagecreatefromjpeg ($IMGSRC);
Imagecopyresampled ($image _wp, $image, 0, 0, 0, 0, $new _width, $new _height, $width, $height);
75 represents the quality, compressed picture capacity size imagejpeg ($image _wp, $IMGDST, 75);
Imagedestroy ($image _wp);
Break
Case 3:header (' content-type:image/png ');
$image _wp=imagecreatetruecolor ($new _width, $new _height);
$image = Imagecreatefrompng ($IMGSRC);
Imagecopyresampled ($image _wp, $image, 0, 0, 0, 0, $new _width, $new _height, $width, $height);
75 represents the quality, compressed picture capacity size imagejpeg ($image _wp, $IMGDST, 75);
Imagedestroy ($image _wp);
Break
}
}