首页 > 其他 > 详细

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

时间:2021-05-08 23:11:39      阅读:33      评论:0      收藏:0      [点我收藏+]
$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);
}

}

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

原文:https://www.cnblogs.com/F4natasy/p/14745901.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!