Laravel Class Intervention Image not found

854 views Asked by At

I'm new to Laravel, I use Intervention Image on laravel 10.39.0, but it is getting error, Class "Intervention\Image\Facades\Image" not found

This is the code.

This is the code.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Intervention\Image\Facades\Image;


class HomeController extends Controller
{
    public function index(){
        return view('home');
    }

    public function test(){
        // Open an image file
        $img = Image::make('uploads/img1.jpg');
        $img->crop(300,300);
        $img->save(public_path('uploads/corp_img1.jpg'));
        
    }
}

error is showing on this line: $img = Image::make('uploads/img1.jpg'); "intervention/image": "^3.2", PHP: PHP 8.2.10-2ubuntu1

How to solve this issue?

2

There are 2 answers

0
Ali Yousefi On

First check the intervention/image is installed correctly you can check first this directory vendor/intervention/image or composer show intervention/image.
if you can see this directory try this commands composer dump-autoload.
then you can try to clear cache php artisan cache:clear after that try again and check is problem exists.

2
DilMAX On

After a couple of hours, I found the answer, this code might be helpful to others.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Intervention\Image\ImageManager;
use Intervention\Image\Drivers\Gd\Driver;


class HomeController extends Controller
{
    public function index() 
    {
        return view('home');
    }

    public function test() 
    {
        // create image manager with desired driver
        $manager = new ImageManager(new Driver());

        // read image from file system
        $image = $manager->read('uploads/image.jpeg');
        // Image Crop
        $image->crop(500,500);
        // insert watermark
        $image->place('uploads/water_mark.png');
        //Save the file
        $image->save(public_path('uploads/crop.jpeg'));
    }
}