[英]How to set image size and dimension in Intervention Image package using Laravel
我正在使用干预图像包来操作上传的图像,然后再将其保存到服务器。 我已经成功设置了图像的尺寸,它工作正常,但我想修复图像大小,即生成的图像应小于等于30KB,并且分辨率仅为300 dpi。
这是代码,我用来调整上传图像的大小:
$file = $post->file('profile_image');
$filename = Carbon::now()->timestamp.'_'.$file->getClientOriginalName();
\Image::make($file->getRealPath())->resize(160, 160)->save('uploads/profile/'.$filename);
如果我的担忧对干预图像包可行,请给我一个解决方案。
提前致谢。
你可以尝试这样的事情
$size = 160;
$img = \Image::make($file->getRealPath())->resize($size, $size)->save('uploads/profile/'.$filename);
while($img->filesize() < "someAmount"){
$size = (int)$size - 20; // adjust based on your need
$img = \Image::make($file->getRealPath())->resize($size, $size)->save('uploads/profile/'.$filename);
}
注意这不是正确的答案,但解决这个问题是个好主意
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.