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()
Aniruddh Parihar
  • 3,072
  • 3
  • 21
  • 39
DMS-KH
  • 2,669
  • 8
  • 43
  • 73

4 Answers4

21

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;
Seunope
  • 4,784
  • 2
  • 24
  • 30
2

Make Sure that In config/app update Providers with

Intervention\Image\ImageServiceProvider::class

and update aliases with

'Image' => Intervention\Image\Facades\Image::class,
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();

Asra Fud Duha
  • 511
  • 5
  • 9
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.");
}
}
  • 1
    Please provide additional details in your answer. As it's currently written, it's hard to understand your solution. – Community Sep 09 '21 at 12:34