Laravel 5图片调整大小 [英] Laravel 5 image resize
本文介绍了Laravel 5图片调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Laravel 5并有一个上传图片的表格.保存文件时,我可以在控制器方法中获取图像并将其放置在目录中:
I use Laravel 5 and have a form to upload a image. When saving the file I have in my controller methods to get the image and put it in a directory:
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中是否有图像调整大小或压缩功能? 最好的主意是什么?
Before I save the file I would like to resize the file with a max. width of 800px. Is there a image resize or compression function in Laravel available? What would be the best idea to do this?
推荐答案
您可以安装和使用软件包,类似于干预.
You can install and use package, similar to intervention.
来自官方网站的示例:
$img = Image::make('public/foo.jpg');
$img->resize(320, 240);
$img->insert('public/watermark.png');
$img->save('public/bar.jpg');
这篇关于Laravel 5图片调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文