Image Intervention w/ Laravel 5.4 Storage

后端 未结 10 847
执笔经年
执笔经年 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 04:00

    You can't store an \Intervention\Image\Image object directly with the Laravel 5 filesystem. What you can do is resize the image from your request, and save it under the same tmp path. Then just store the uploaded (overwritten) file to the filesystem.

    Code:

    $image  = $request->file('createcommunityavatar');
    //resize and save under same tmp path
    $resize = Image::make($image)->fit(300)->save();
    // store in the filesystem with a generated filename
    $store  = $image->store('image', 'public');
    // get url from storage
    $url    = Storage::url($store);
    

提交回复
热议问题