我在Laravel 10应用程序上安装了Interaction/Image 3.5,但收到错误:

找不到类"干预\图像\驱动程序\GD\驱动程序"

代码为:

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

我是否需要一些选项来访问/app.php?

出什么问题了?

推荐答案

虽然class names in PHP不区分大小写,file names on a Unix-like system are.因此,当自动加载器寻找类Intervention\Image\Drivers\GD\Driver时,它试图打开vendor/intervention/image/src/Drivers/GD/Driver.php,但实际的文件是vendor/intervention/image/src/Drivers/Gd/Driver.php(小写的"d"在"Gd"中).

您只需更改这一行:

use Intervention\Image\Drivers\GD\Driver;

致:

use Intervention\Image\Drivers\Gd\Driver;

Php相关问答推荐

如何使用属性#[Embedded]嵌入带有规则的对象集合?

如何修复警告:当使用WordPress get_the_Terms()时,Foreach()参数必须是ARRAY|OBJECT类型?

有没有办法为整个PHP应用程序启用严格类型

由于某种原因,FILE_GET_CONTENTS从一天到另一天停止工作,并在PHP 7.2.34中返回一条&http/1.1 406不能接受&的错误

Symfony5:如何在不登录的情况下使API路由可访问?

返回WooCommerce中的所有已启用变体

Codeigniter 4中的未定义变量$HOME

如何用Ubuntu 22.04在VSCode中启用XDebug

订单完成后创建 WooCommerce 促销代码

使用产品自定义字段作为 WooCommerce 中特定用户角色的折扣百分比

Woocommerce的数量和价格条件

Woocommerce注册中的自定义复选框验证错误提示问题

PHP使用三元运算符进行null合并(再次)

自定义主键值未正确显示

为 WordPress 页面创建新功能

使用来自 PHP 表单的数据更新 xml 命名空间

在帖子内容中使用短代码触发 Woocommerce 挂钩

password_verify 在 PHP 7.4 中有效,但在 PHP 8.2 中无效

来自命令行的 PHP 没有给出正确的结果

Laravel 响应 html 默认页面忽略控制器