缩小图片比例大小和占用空间

$resource_path = env('APP_URL') . $hotel->hero_image;
$name = explode('.', $resource_path);

if(!file_exists('upload/hotel/thumb/'.$id.'.'.$name[2]))

{

$s_size = getimagesize($resource_path);

$s_height = $s_size[1];

$s_width = $s_size[0];

$d_height = $s_size[1]/3;

$d_width = $s_size[0]/3;
$dest = imagecreatetruecolor($d_width, $d_height);
if (strpos($name[2],'png')!==false){
$source = imagecreatefrompng($resource_path);
imagecopyresized($dest, $source, 0, 0, 0, 0, $d_width, $d_height, $s_width, $s_height);

imagepng($dest,'upload/hotel/thumb/'.$id.'.'.$name[2],1);
}else{
$source = imagecreatefromjpeg($resource_path);
imagecopyresized($dest, $source, 0, 0, 0, 0, $d_width, $d_height, $s_width, $s_height);

imagejpeg($dest,'upload/hotel/thumb/'.$id.'.'.$name[2],100);
}

}
posted @ 2021-05-08 17:35  F4ntasy  阅读(86)  评论(0编辑  收藏  举报

對不起,您的瀏覽器不支持Flash


請使用支持Flash的瀏覽器訪問本頁,謝謝!