Resize image in Laravel 5.2

前端 未结 3 1141
甜味超标
甜味超标 2020-12-08 11:52

Can anyone help me how to implement resizing image in Laravel?

I have this code only:

if($request->hasFile(\'image\')){
    if (Input::file(\'imag         


        
3条回答
  •  眼角桃花
    2020-12-08 11:58

    I would recommend Intervention Image for this task.

    Simply install it with composer

    composer require intervention/image
    

    and just use it like this:

    \Intervention\Image\ImageManagerStatic::make('public/foo')->fit(100)->save($path);
    

    Remarks

    • Service Provider The intervention image provides a Service Provider for Laravel. You may add the service provider manually as explained here. After that, you may push the configuration file to Laravel. However, the configuration has only one option and that is the image driver. gd is default , so if you don't want to change it, there is no need to use the service provider and configuration.

    • Alias Instead of the service Provider, you could create an alias in config/app:

      'Image' => Intervention\Image\ImageManagerStatic::class
      

      Then you can use it like this:

      \Image::make('public/foo')->fit(100)->save($path);
      
    • Testing You can still Laravel's file upload tests when using intervention image. For details, see How to fake image upload for testing with Intervention image package using Laravel

提交回复
热议问题