Image Intervention w/ Laravel 5.4 Storage

后端 未结 10 842
执笔经年
执笔经年 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:53

    The put method works with the Image intervention output. The putFile method accepts either an Illuminate\Http\File or Illuminate\Http\UploadedFile instance.

    $photo = Image::make($request->file('photo'))
      ->resize(400, null, function ($constraint) { $constraint->aspectRatio(); } )
      ->encode('jpg',80);
    
    Storage::disk('public')->put( 'photo.jpg', $photo);
    

    The above code resizes the uploaded file to 400px width while holding the aspect ratio. Then encodes to jpg at 80% quality. The file is then stored to the public disc. Note you must provide a filename, not just the directory.

提交回复
热议问题