在Laravel中调整上传的图像大小并在S3中存储不起作用

Alv*_*ker 5 php amazon-s3 laravel laravel-5

我正在尝试将几个已调整大小的图像上传到S3,但不知何故所有图像都具有相同的大小.以不同尺寸在本地存储它们不会产生任何问题.我错过了什么?

public function uploadFileToS3(Request $request) {
    $image = Image::make($request->file('image'))->encode('jpg', 75);
    $s3 = Storage::disk('s3');

    $image_file_name = $this->generateName($request->name) . '.jpg';
    $file_path = '/' . config('folder') . '/' . $request->name . '/';

    $s3->put($file_path.'original_'.$image_file_name, $image, 'public');
    $s3->put($file_path.'medium_'.$image_file_name, $image->fit(300, 300), 'public');
    $s3->put($file_path.'thumb_'.$image_file_name, $image->fit(100, 100), 'public');

    return json_encode(array(
        'filename' => $image_file_name
    ));
}
Run Code Online (Sandbox Code Playgroud)

所有版本都成功存储在S3中,只有所有版本都具有相同的大小

Lan*_*och 7

我有两种可能的解决方案.

尝试存储它们之前,请尝试完全执行图像处理:

$s3->put($file_path.'original_'.$image_file_name, $image, 'public');
$image->fit(300, 300);
$s3->put($file_path.'medium_'.$image_file_name, $image, 'public');
$image->fit(100, 100);
$s3->put($file_path.'thumb_'.$image_file_name, $image, 'public');
Run Code Online (Sandbox Code Playgroud)

尝试将图像转换为字符串,实际输出文件内容应该正常工作:

$s3->put($file_path.'original_'.$image_file_name, (string) $image, 'public');
Run Code Online (Sandbox Code Playgroud)