/** * If this image doesn't already have an original image file backed up, * move the current image file to be the backup. * * @param FileManager $fileManager * * @return bool */ public function moveOriginalFile(FileManager $fileManager) { if ($this->hasOriginal()) { return true; } // Backup uncropped image $originalImageFile = $this->getImageFile(); $fileManager->moveFile($originalImageFile, FileManager::UNCROPPED_DIR); $this->setUncroppedImageFile($originalImageFile); return true; }
/** * @api {put} /images/{imageId}/image?action=revert Revert an Image * @apiGroup Manipulating Images * @apiDescription Revert the changes made by a prior crop/annotate operation. * Returns an error if the image is not altered. * This does not undo rotation - you can rotate it back to the original orientation. * @apiParam {string=revert} action Action to perform. * @apiUse RequiresEditableImage * @apiUse ImageSuccessResponse * * @param Image $image * @param FileManager $fileManager * * @return Response */ protected function revert(Image $image, FileManager $fileManager) { $this->requireEditableImage($image); if ($image->operationInProgress) { throw new HttpException(409, "Another operation is currently in progress for this image."); } $image->operationInProgress = true; $image->save(); if (!$image->hasOriginal()) { throw new HttpException(400, "Image is not altered."); } $originalImageFile = $image->getUncroppedImageFile(); if (!$originalImageFile) { throw new HttpException(500, "Unable to find original image."); } // Copy back uncropped image $fileManager->moveFile($originalImageFile, FileManager::IMAGE_DIR); $image->setImageFile($originalImageFile); $image->setUncroppedImageFile(null); $image->operationInProgress = false; $success = $image->save(); return $this->response(['success' => $success, 'image' => $image->fresh()]); }