Call to undefined method Intervention\Image\Facades\Image::make()
Asked Answered
S

5

6

I upgraded from Laravel 4.2 to Laraveld5.3 with intervention/image : "^2.3",

 if (Input::hasFile('logo')) {

        $path = public_path()."/assets/admin/layout/img/";
        File::makeDirectory($path, $mode = 0777, true, true);

        $image      = Input::file('logo');
        $extension  = $image->getClientOriginalExtension();
        $filename   = "logo.$extension";
        $filename_big   = "logo-big.$extension";

        Image::make($image->getRealPath())->save($path.$filename);
        Image::make($image->getRealPath())->save($path.$filename_big);

        $data['logo']   =   $filename;

    }

The result Is, got the error below:

Call to undefined method Intervention\Image\Facades\Image::make()
Sirius answered 1/11, 2016 at 2:24 Comment(0)
C
22

I experienced the same issue in my Laravel 5.4 project. I stumble on this link

that help resolve the issue. This was the fix that was provided

In config/app change 'aliases' for Image from

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

To

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

Then in your controller header add

use Image;
Curvaceous answered 9/6, 2017 at 13:28 Comment(0)
H
2

Make Sure that In config/app update Providers with

Intervention\Image\ImageServiceProvider::class

and update aliases with

'Image' => Intervention\Image\Facades\Image::class,
Herminiahermione answered 26/3, 2019 at 17:59 Comment(0)
D
0
  1. In your config/app.php file, add

Intervention\Image\ImageServiceProvider::class,

in providers array and add

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

in aliases array.

  1. Run

php artisan config:cache

command.

  1. In your controller add

use Image;

before class definition.

  1. Now you can use the Image class according to your needs inside the controller's function. suppose,

$imageHeight = Image::make($request->file('file'))->height();

Disarm answered 31/12, 2020 at 0:17 Comment(0)
X
0
 public function optimizeFile(Request $request)
{
    $data = $request->file('image');
    // dd($data);
if ($request->hasFile('image')) {

    foreach($data as  $key => $val){

            $path=storage_Path('app/public/');
            $filename='image-'.uniqid().$key.'.'.'webp';
            $val->move($path,$filename); 
            $p['image']=$filename;
            $insert[$key]['image'] = $filename;

      

        //Resize image here
        $thumbnailpath[$key]['abc'] = storage_path('app/public/'.$filename);
      
        $img = Image::make($thumbnailpath)->resize(400, 150, function($constraint) {
            $constraint->aspectRatio();
        });
        $img->save($thumbnailpath);
    }

    return redirect('ROUTE_URL')->with('success', "Image uploaded successfully.");
}
}
Xylon answered 9/9, 2021 at 12:11 Comment(1)
Please provide additional details in your answer. As it's currently written, it's hard to understand your solution.Samaria
C
0

If you're using intervention/image V3 then make is replaced with read

https://image.intervention.io/v3/introduction/upgrade

Cenac answered 20/3 at 8:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.