[PHP] php class picture compression

<? PHP
/ **
* @ param $ imgName file path
* @ param $ seek thumbnail rename
* @ param $ width thumbnail width
* @ param $ height thumbnail height
* @ param $ slt_img_url thumbnail save path
*
* /
minimg {class
public function SLT ($ imgName, Seek $, $ width, height $, $ slt_img_url) {
// get a new size
List ($ width_orig, height_orig $) = $ = imgma the getimagesize ($ imgName);

$ = $ ratio_orig width_orig / $ height_orig;
IF ($ width / height $> $ ratio_orig) {
$ width * height = $ $ ratio_orig;
} the else {
@ $ $ height = width / $ ratio_orig;
}

// 重新取样
@$image_p = imagecreatetruecolor($width, $height);
if($imgma[2] == 2){
$image = imagecreatefromjpeg($imgname);
if($image){

$imgurl = $slt_img_url."slt_"."$seek.jpg";
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, $imgurl, 100);
return $imgurl;
}

}
if($imgma[2] == 3){
$image = imagecreatefrompng($imgname);
if ($image) {

$imgurl = $slt_img_url."slt_"."$seek.png";
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagepng($image_p, $imgurl, 9);
return $imgurl;

}
}
if($imgma[2] == 4){
$image = imagecreatefromgif($imgname);
if ($image) {

$imgurl = $slt_img_url."slt_"."$seek.gif";
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagepng($image_p, $imgurl, 9);
return $imgurl;
}
}
}
}
set_time_limit(0);

 

Call the method:

minimg new new minimg = $ ();
$ = $ minimg- minimg_url> SLT ( "image path ',' thumbnail name ',' maximum width ',' maximum height ',' storage path '); // default geometric scaling

 

Guess you like

Origin www.cnblogs.com/shinrin/p/11621951.html