laravel intervention/image处理上传的图片

场景:   

      网站上传头像需要存储的只是缩略图, 节省存储空间

安装(需要使用php的gd扩展):

        1. composer require  intervention/image  

        2. config/app.php 添加 

            \Intervention\Image\ImageServiceProvider::class,

            'Image' => \Intervention\Image\Facades\Image::class,

简单使用:

$file = $request->file('avatar');
$destinationPath = 'uploads/';
$filename = \Auth::id() . time() . $file->getClientOriginalName();

$file->move($destinationPath, $filename);
Image::make($destinationPath . $filename)->fit(200)->save();

  

    


你可能感兴趣的:(laravel)