我使用 Laravel 5 并有一个上传图像的表单。保存文件时,我在 Controller 方法中获取图像并将其放入目录中:
if ($request->hasFile('picture')) {
$destinationPath = 'uploads';
$filename = $image->getClientOriginalName();
$extension = $image->getClientOriginalExtension(); // add
$picture = sha1($filename . time()) . '.' . $extension; //add
$offer->image = $picture;
$image->move($destinationPath, $picture);
}
$offer->save();
在保存文件之前,我想将文件大小调整为最大。宽度为 800 像素。 Laravel 中有图像调整大小或压缩功能吗? 这样做最好的主意是什么?
最佳答案
您可以安装并使用包,类似于intervention .
官网示例:
$img = Image::make('public/foo.jpg');
$img->resize(320, 240);
$img->insert('public/watermark.png');
$img->save('public/bar.jpg');
关于Laravel 5 调整图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36133906/