Image Intervention w/ Laravel 5.4 Storage

后端 未结 10 843
执笔经年
执笔经年 2021-02-05 03:16

I\'m using the storage facade to store a avatar which works fine, but I want to resize my image like I did in previous versions of laravel. How can I go about doing this? Here i

10条回答
  •  失恋的感觉
    2021-02-05 03:39

    The cleanest solution I could find—using the native Storage facade—is the following. I can confirm that this works in Laravel 5.7, using intervention/image version 2.4.2.

    $file = $request->file('avatar');
    $path = $file->hashName('public/avatars');
    $image = Image::make($file)->fit(300);
    Storage::put($path, (string) $image->encode());
    
    $url = Storage::url($path);
    

提交回复
热议问题