在yii2中找不到类'Imagine\Gd\Imagine'

6
我正在开发图像裁剪模块,需要获取上传图片的详细信息,所以我使用了这个函数。
$image = Image::getImagine()->open($path);
$size = $image->getSize();

使用此函数时,出现错误。

Class 'Imagine\Gd\Imagine' not found

                case self::DRIVER_IMAGICK:
                    if (class_exists('Imagick', false)) {
                        return new \Imagine\Imagick\Imagine();
                    }
                    break;
                case self::DRIVER_GD2:
                    if (function_exists('gd_info')) {
                        return new \Imagine\Gd\Imagine();
                    }
                    break;
                default:
                    throw new InvalidConfigException("Unknown driver: $driver");
            }
        }
        throw new InvalidConfigException("Your system does not support any of these drivers: " . implode(',', (array) static::$driver));

这个错误来自于IT库文件。

vendor\yiisoft\yii2\imagine\BaseImage.php

我该如何解决这个问题?有人能给我建议吗?

命名空间也已添加。

namespace yii\imagine;

use Yii;

use yii\imagine\Image\Box;
use yii\imagine\Image\Color;
use yii\imagine\Image\ImageInterface;
use yii\imagine\Image\ImagineInterface;
use yii\imagine\Image\ManipulatorInterface;
use yii\imagine\Image\Point;



use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
use yii\helpers\ArrayHelper;

这是库文件,我从未更改过它,我也执行了composer update,但仍然出现相同的错误。

1个回答

4
可能是命名空间访问问题,请尝试添加。
 use yii\imagine;

为您的代码


你在哪里调用了 use yii\imagine; 函数? - ScaisEdge
@HusnainAslam,针对上面的评论,你必须在调用函数时添加"use yii\imagine;"。 - ScaisEdge

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接