mstdmstd
mstdmstd

Reputation: 3131

Why calling Intervention\Image raised error Drivers\GD\Driver not found?

I installed intervention/image 3.5 on Laravel 10 app and got error :

Class "Intervention\Image\Drivers\GD\Driver" not found

With code :

use Intervention\Image\ImageManager;
use Intervention\Image\Drivers\GD\Driver;

class GetImageProps
{
    public static function get(string $imageType, string $imagePath = null): array
    {
        $retArray = [];
        $storageFullImagePath = base_path() . '/storage/app/' . $imagePath;
        try {
            $manager = new ImageManager(new Driver()); // Error pointing this line
            $targetImage = $manager->read($storageFullImagePath);

I check that package is installed ok :

$ composer show intervention/image
name     : intervention/image
descrip. : PHP image manipulation
keywords : gd, image, imagick, resize, thumbnail, watermark
versions : * 3.5.0
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : https://image.intervention.io/
source   : [git] https://github.com/Intervention/image.git 408d3655c7705339e8c79731ea7efb51546cfa10
dist     : [zip] https://api.github.com/repos/Intervention/image/zipball/408d3655c7705339e8c79731ea7efb51546cfa10 408d3655c7705339e8c79731ea7efb51546cfa10
path     : /mnt/_work_sdb8/wwwroot/lar/NewsPublisher/vendor/intervention/image
names    : intervention/image

support
issues : https://github.com/Intervention/image/issues
source : https://github.com/Intervention/image/tree/3.5.0

autoload
psr-4
Intervention\Image\ => src

requires
ext-mbstring *
intervention/gif ^4.0.1
php ^8.1

requires (dev)
mockery/mockery ^1.6
phpstan/phpstan ^1
phpunit/phpunit ^10.0
slevomat/coding-standard ~8.0
squizlabs/php_codesniffer ^3.8

suggests
ext-exif Recommended to be able to read EXIF data properly.

In output of phpinfo :

PHP Version 8.2.16

gd
GD Support  enabled
GD headers Version  2.3.3
GD library Version  2.3.3
FreeType Support    enabled

Do I need to some options to config/app.php ?

What is wrong ?

Upvotes: 2

Views: 1052

Answers (2)

francisco
francisco

Reputation: 2140

By the documentantion, Intervention Image is currently shipped with two different drivers. Depending on your PHP installation, you can choose between GD or Imagick.

Intervention\Image\Drivers\Gd\Driver
Intervention\Image\Drivers\Imagick\Driver

You can do in many forms of code, with this you don't need the use namespace of the driver:

use Intervention\Image\ImageManager;

// create new image manager with gd driver
$manager = ImageManager::gd();

Upvotes: -3

IMSoP
IMSoP

Reputation: 98005

Although class names in PHP are not case sensitive, file names on a Unix-like system are. So when the autoloader looks for the class Intervention\Image\Drivers\GD\Driver it tries to open vendor/intervention/image/src/Drivers/GD/Driver.php but the actual file is vendor/intervention/image/src/Drivers/Gd/Driver.php (lower-case "d" in "Gd").

You just need to change this line:

use Intervention\Image\Drivers\GD\Driver;

to:

use Intervention\Image\Drivers\Gd\Driver;

Upvotes: 3

Related Questions