各位大神文章的缩略图一般怎么处理呀
各位大神文章缩略图都怎么做的呀,我的目前是这样一个逻辑:
1、判断文章里面有没有图片,这个我写在一个helper里面;
2、判断图片的尺寸,长宽小于特定的值就选用默认图片;
3、文章没有图片也使用默认图片,下附代码:
function get_postImg($content,$imgname){
$result = preg_match('/<img.+src=\"?(.+\.(jpg|jpeg|gif|bmp|bnp|png))\"?.+>/i',$content,$searchImg);
if ($result){
$img = \Intervention\Image\Facades\Image::make($searchImg[1])->resize(800,null,function ($constraint){
$constraint->aspectRatio();
});
$height = $img->height();
if ($height >= 400){
$img->crop(800,400);
$img->save(public_path().'/'.'pic/posts/thumb/'.$imgname.'.jpg');
return 'pic/posts/thumb/'.$imgname.'.jpg';
}
else{
return 'pic/posts/thumb/post_default.jpg';
}
}
else{
return 'uploads/images/hotposts/hot_default.jpg';
}
}
因为项目小,所以直接上传在云服务器,没有上传到第三方,然后数据库存储地址。
个人思路,求指导
推荐文章: