使用干预调整图像大小

时间:2015-07-16 16:24:03

标签: php laravel amazon-s3 laravel-5 intervention

我尝试使用AWS S3干预,但调整大小的方法对我不起作用。

$img = Image::make($file)->rotate($rotate)->crop($width, $width, $x, $y);
$img->backup();

foreach(Config::get('img.image-sizes') as $_k => $_v){
    $img->resize($_v['w'], $_v['h']);
    $s3->queue($img, $name);
    $img->reset();
}

图像上传到S3很好,但调整大小失败,我得到原始图像大小的所有图像

如果我在图像上调用save(),则调整大小有效,但我不希望保存图像,因为我通过S3上传,将$ img作为正文:

$this->commands[] = $this->s3->getCommand('PutObject', [
        'Bucket' => env('AWS_BUCKET'),
        'Key' => Config::get('img.image-path').$name,
        'Body' => $img,
        'ContentType' => $img->mime(),
        'ACL' => 'public-read'
    ]);

为了让这个工作,我必须先为每个图像调用保存吗?如果是这样有一种方法可以让它与S3玩得很好,理想情况下我不想先将它们保存到我的服务器,然后再将它们发送到S3。

1 个答案:

答案 0 :(得分:0)

这是我使用Laravel 5和Intervention来调整上传图像大小并保存到Amazon S3的代码。

$imageFile = \Image::make($imageUpload)->resize(600, 600)->stream();
$imageFile = $imageFile->__toString();

$filename = 'myFileName.png';

$s3 = \Storage::disk('s3');
$s3_response = $s3->put('/'.$filename, $imageFile, 'public');
相关问题