Php 如何使用Laravel设置干预图像包中的图像大小和尺寸
我正在使用干预映像包在将上载的映像保存到服务器之前对其进行操作。我已经成功设置了图像的尺寸,它工作正常,但我想固定图像大小,即生成的图像应该小于等于30KB,并且应该只有300dpi的分辨率 下面是我用来调整上传图像大小的代码:Php 如何使用Laravel设置干预图像包中的图像大小和尺寸,php,laravel,image,laravel-5.8,intervention,Php,Laravel,Image,Laravel 5.8,Intervention,我正在使用干预映像包在将上载的映像保存到服务器之前对其进行操作。我已经成功设置了图像的尺寸,它工作正常,但我想固定图像大小,即生成的图像应该小于等于30KB,并且应该只有300dpi的分辨率 下面是我用来调整上传图像大小的代码: $file = $post->file('profile_image'); $filename = Carbon::now()->timestamp.'_'.$file->getClientOriginalName(); \Image::make(
$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);
而($img->filesize()<“someAmount”){
$size=(int)$size-20;//根据需要进行调整
$img=\Image::make($file->getRealPath())->resize($size,$size)->save($uploads/profile/”。$filename);
}
注意这不是正确答案,但解决这个问题是个好主意
您好Kamlesh,谢谢您的回复,但是如何将图像分辨率设置为300度