为什么调用 Intervention\Image 会引发错误 Drivers\GD\Driver not found?

问题描述 投票:0回答:1

我在 Laravel 10 应用程序上安装了 Intervention/image 3.5 并收到错误:

未找到类“Intervention\Image\Drivers\GD\Driver”

有代码:

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);

我检查软件包是否安装正常:

$ 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.

在 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

我需要 config/app.php 的一些选项吗?

出了什么问题?

php laravel intervention
1个回答
0
投票

通过文档,按照以下步骤安装:

require './vendor/autoload.php';
 
use Intervention\Image\ImageManager;
use Intervention\Image\Drivers\Imagick\Driver;

// create new manager instance with desired driver
$manager = new ImageManager(new Driver());

TLDR:更正一下,您的代码是:

use Intervention\Image\Drivers\GD\Driver;

这是:

use Intervention\Image\Drivers\Imagick\Driver;
© www.soinside.com 2019 - 2024. All rights reserved.