Laravel 5 调整图像大小

标签 laravel laravel-5

我使用 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/

相关文章:

Laravel 5.2 JSON 对带有错误 api_token 的请求的响应

laravel - 如何根据请求发送Blob文件以保存在laravel中

php - $浏览器->调整大小(INT,INT);不再适合我?

php - 从 Eloquent 集合中删除不匹配的条件记录

php - Elastic Beanstalk 在启用 ZipArchive 的情况下编译 php

php - Laravel 4 从子查询中的另一个表中选择列

php - 数组索引自动从 1 开始

php - Laravel - 干预图像 - 图像源不可读

laravel - 测试 assertDispatched 仅在使用事件助手时有效

日志记录在 Laravel 队列作业中不起作用