/** * @inheritdoc */ public function beforeValidate() { if (!parent::beforeValidate()) { return false; } if ($this->image) { $content = file_get_contents($this->image->tempName); $extension = $this->image->getExtension(); if (!($preview = Yii::$app->preview->save($content, $extension))) { return false; } $this->preview = $preview; } return true; }