Reputation: 61
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?
Upvotes: 3
Views: 9279
Reputation: 165
Since you're using Laravel, you need to install the Laravel-specific version of the Intervention Image package by running the following command:
composer require intervention/image-laravel
You can find the documentation here
About your error:
I think you are using some general package of the intervention
package, which is composer require intervention/image
. However, if you want this package to use then you will need more configurations like as mentioned in their general documentation here
Upvotes: 1
Reputation: 2795
For those still having issues, there is now an official Intervention/Image
integration meant for Laravel only, which you can find on https://github.com/Intervention/image-laravel or you can instead still install the v2 of Intervention/Image
.
Upvotes: 0
Reputation: 1
Newer versions of Intervention Image don't have the Facade, I don't know why. The owner has to update their website documentation for Laravel.
With "intervention/image": "^2.5"
, you can find this route
vendor/intervention/image/src/Intervention/Image/Facades/Image.php
With "intervention/image": "^3.5"
, that route is no longer there.
Upvotes: 0
Reputation: 61
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'));
}
}
Upvotes: 3
Reputation: 712
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.
Upvotes: 0