Class' Imagine \ Gd \ Imagine'找不到
我在yii2中使用了cropbox扩展程序,它正在通过此错误 虽然名称空间yii / imag用于模型文件
以下是模型类文件
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()
);
}
}
请帮助我!!