Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jim1506's avatar

Problem with Intervention Image and Laravel 11

0

I am having a problem with intervention image and Laravel 11. I am upgrading a program which is fine with Laravel 10.

I installed with

composer require intervention/image-laravel and then ran

php artisan vendor:publish --provider="Intervention\Image\Laravel\ServiceProvider" I have also installed Unisharp's filemanager and I notice that the composer.json file has these two entries

"intervention/image": "^3.11", "intervention/image-laravel": "^1.5", I have a function to resize which includes

if (!file_exists($image2)) { //200 wide if (file_exists($image)) { $destinationPath = $path2; $imgsave2 = $destinationPath . '/' . $img; $img2 = Image::read($image); $img2 ->resize(200, null, function ($constraint) { $constraint->aspectRatio(); }) ->save($imgsave2); } } (This simply takes in the image as image2 and the destination path and places it in a subdirectory based on the image size, hence the destination path). This function has

use Intervention\Image\Laravel\Facades\Image; at the top

When I first tried to use this I had am image that it could not find Image so I setup a facade as

class AliasServiceProvider extends ServiceProvider { /** * Register services. */ public function register(): void { $loader = AliasLoader::getInstance(); $loader->alias('Image', Intervention\Image\Laravel\Facades\Image::class); }

/**
 * Bootstrap services.
 */
public function boot(): void
{
    //
}

Also in the providers in the bootstrap directory I have:

App\Providers\AliasServiceProvider::class, Now when I try to use it I am getting an error

Unable to resolve driver. Argument must be either an instance of Intervention\Image\Interfaces\DriverInterface::class or a qualified namespaced name of the driver class.

I am going around and around with this any help would be very greatly appreciated.

0 likes
2 replies
jim1506's avatar

Thanks so much. What a stupid mistake. I amended my use section to

use Intervention\Image\Laravel\Facades\Image; use Intervention\Image\ImageManager; use Intervention\Image\Drivers\Gd\Driver;

and then amended the function to:

if (file_exists($image)) { $destinationPath_200 = $path2; $imgsave = $destinationPath_200 . '/' . $img; $manager = new ImageManager(new Driver()); $new = $manager->read($image); $new->scale(width:200); $new->toPng()->save($imgsave); }

and it works perfectly.

Thanks again. I admit being an idiot!

1 like

Please or to participate in this conversation.