在yii2中找不到类imagine/gd/imagine
未找到类“Imagine\Gd\Imagine” 我在yii2中使用cropbox扩展,它正在克服这个错误 尽管在模型文件中使用了名称空间yii/imagine 下面是模型类文件在yii2中找不到类imagine/gd/imagine,yii2,Yii2,未找到类“Imagine\Gd\Imagine” 我在yii2中使用cropbox扩展,它正在克服这个错误 尽管在模型文件中使用了名称空间yii/imagine 下面是模型类文件 namespace app\models; use Yii; use yii\imagine; use yii\imagine\Image; // use yii\imagine\Gd; use yii\helpers\Json; use Imagine\Image\Box; use Imagine\Image\Po
namespace app\models;
use Yii;
use yii\imagine;
use yii\imagine\Image;
// use yii\imagine\Gd;
use yii\helpers\Json;
use Imagine\Image\Box;
use Imagine\Image\Point;
/**
* This is the model class for table "tbl_slider_pics".
*
* @property integer $id
* @property string $path
* @property integer $status
* @property string $ip
* @property string $crt_by
* @property string $crt_time
* @property string $mod_by
* @property string $mod_time
*/
class TblSliderPics extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public $image;
public $crop_info;
public static function tableName()
{
return 'tbl_slider_pics';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['path'], 'required'],
[['status'], 'integer'],
[['path'], 'string', 'max' => 2000],
[['ip'], 'string', 'max' => 30],
[['crt_by', 'mod_by'], 'string', 'max' => 50],
[['crt_time', 'mod_time'], 'string', 'max' => 20],
[
'image',
'image',
'extensions' => ['jpg', 'jpeg', 'png', 'gif'],
'mimeTypes' => ['image/jpeg', 'image/pjpeg', 'image/png', 'image/gif'],
],
['crop_info', 'safe'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'path' => 'Path',
'status' => 'Status',
'ip' => 'Ip',
'crt_by' => 'Crt By',
'crt_time' => 'Crt Time',
'mod_by' => 'Mod By',
'mod_time' => 'Mod Time',
];
}
public function afterSave($insert, $changedAttributes)
{
// open image
$image = Image::getImagine()->open($this->image->tempName);
// rendering information about crop of ONE option
$cropInfo = Json::decode($this->crop_info)[0];
$cropInfo['dWidth'] = (int)$cropInfo['dWidth']; //new width image
$cropInfo['dHeight'] = (int)$cropInfo['dHeight']; //new height image
$cropInfo['x'] = $cropInfo['x']; //begin position of frame crop by X
$cropInfo['y'] = $cropInfo['y']; //begin position of frame crop by Y
// Properties bolow we don't use in this example
//$cropInfo['ratio'] = $cropInfo['ratio'] == 0 ? 1.0 : (float)$cropInfo['ratio']; //ratio image.
//$cropInfo['width'] = (int)$cropInfo['width']; //width of cropped image
//$cropInfo['height'] = (int)$cropInfo['height']; //height of cropped image
//$cropInfo['sWidth'] = (int)$cropInfo['sWidth']; //width of source image
//$cropInfo['sHeight'] = (int)$cropInfo['sHeight']; //height of source image
//delete old images
$oldImages = FileHelper::findFiles(Yii::getAlias('/home/sweet947/public_html/fortaj.ca/backend/uploads/'), [
'only' => [
$this->id . '.*',
'thumb_' . $this->id . '.*',
],
]);
for ($i = 0; $i != count($oldImages); $i++) {
@unlink($oldImages[$i]);
}
//saving thumbnail
$newSizeThumb = new Box($cropInfo['dWidth'], $cropInfo['dHeight']);
$cropSizeThumb = new Box(200, 200); //frame size of crop
$cropPointThumb = new Point($cropInfo['x'], $cropInfo['y']);
$pathThumbImage = Yii::getAlias('/home/sweet947/public_html/fortaj.ca/backend/uploads/')
. '/thumb_'
. $this->id
. '.'
. $this->image->getExtension();
$image->resize($newSizeThumb)
->crop($cropPointThumb, $cropSizeThumb)
->save($pathThumbImage, ['quality' => 100]);
//saving original
$this->path->saveAs(
Yii::getAlias('/home/sweet947/public_html/fortaj.ca/backend/uploads/')
. '/'
. $this->id
. '.'
. $this->image->getExtension()
);
}
}
请帮帮我 命名空间问题。。请记住,您必须在使用代码的地方添加“use…..”我也必须在controller中添加它吗?PHP致命错误–yii\base\ErrorException类'Imagine\Gd\Imagine'未找到您是否在配置文件中添加了此扩展名?