public static function saveEditingPhoto($id) { $editable = EditingPhotoActiveRecord::findOne($id); if ($editable == null) { return null; } $photo = PhotoActiveRecord::findOne($editable->photoId); if ($photo == null) { return null; } $image = new Imagick(); $image->readImageBlob($editable->photo); $image = EditingPhotoActiveRecord::filter($editable->filter, $image); if ($editable->reduceNoise != 0) { for ($i = 0; $i < $editable->reduceNoise; $i++) { foreach ($image as $frame) { $frame->enhanceImage(); } } } if ($editable->blur != 0) { foreach ($image as $frame) { $frame->blurImage($editable->blur, 5); } } if ($editable->brightness != 0) { foreach ($image as $frame) { $frame->modulateImage(100 + $editable->brightness, 100, 100); } } $photo->photo = $image->getImagesBlob(); $photo->thumbnail = $editable->thumbnail; if ($photo->save()) { return $editable->delete(); } else { return false; } }
public function actionDeleteimage() { if (Yii::$app->request->isPost && !Yii::$app->user->isGuest && Yii::$app->user->identity->role == 'admin') { $id = Yii::$app->request->post('id'); if ($id != null) { return PhotoActiveRecord::findOne($id)->delete(); } } return false; }
public function actionEdit($id) { $photo = PhotoActiveRecord::findOne($id); $editable = EditingPhotoActiveRecord::createEditingPhoto($photo->id); return $this->render('edit', ['photo' => $editable]); }