DMS-KH
DMS-KH

Reputation: 2787

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

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()

Upvotes: 6

Views: 28240

Answers (5)

Javed A. Baloch
Javed A. Baloch

Reputation: 1070

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

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

Upvotes: 0

user16869645
user16869645

Reputation: 1

 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.");
}
}

Upvotes: 0

Asra Fud Duha
Asra Fud Duha

Reputation: 630

  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();

Upvotes: 0

Taufiqur Rahman
Taufiqur Rahman

Reputation: 78

Make Sure that In config/app update Providers with

Intervention\Image\ImageServiceProvider::class

and update aliases with

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

Upvotes: 2

Seunope
Seunope

Reputation: 4814

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;

Upvotes: 22

Related Questions