Exemple #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     /** @var Image[] $images */
     $images = Image::whereNotNull('expiresAt')->where('expiresAt', '<=', date('Y-m-d H:i:s'))->get();
     foreach ($images as $image) {
         echo "{$image->imageId}\tExpired at {$image->expiresAt}" . PHP_EOL;
         $image->delete();
     }
 }
Exemple #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  * @throws Exception
  */
 public function handle()
 {
     $image = Image::findOrFail($this->argument('imageId'));
     if (!empty($image->thumbnailImageFileId)) {
         if (!$this->option('regenerate')) {
             throw new Exception("Image already has a thumbnail and --regenerate was not set");
         }
         $thumbnail = $image->getThumbnailImageFile();
         \Queue::connection('sync')->push(new DeleteFileJob($thumbnail->getPath()));
         $thumbnail->delete(false);
     }
     \Queue::connection('sync')->push(new MakeThumbnailJob($image->getImageFile()));
 }
 /**
  * Execute the job.
  *
  * @param FileManager $fileManager
  *
  * @throws Exception
  */
 public function handle(FileManager $fileManager)
 {
     $this->logger = $this->getJobLogger();
     $this->logger->debug("Generating thumbnail for image {$this->imageFile->getId()} {$this->imageFile->getPath()}" . " attempt {$this->attempts()}", $this->imageFile->toArray());
     // Get a fresh copy from the DB (checks if it's deleted)
     if (!($this->imageFile = $this->imageFile->fresh())) {
         throw new Exception("ImageFile no longer exists.");
     }
     // Get full size image
     $picture = $fileManager->getPictureForImageFile($this->imageFile);
     $filename = $this->imageFile->getFilename();
     // Generate 200x200 thumbnail
     $picture->fit(200, 200, function (Constraint $constraint) {
         $constraint->upsize();
     });
     if ($thumbnailImageFile = $fileManager->savePicture($picture, 'thumb', $filename, $this->imageFile)) {
         Image::where('imageFileID', $this->imageFile->getId())->update(['thumbnailImageFileId' => $thumbnailImageFile->getId()]);
     }
 }
Exemple #4
0
 /**
  * @param Image           $image
  * @param DatabaseManager $db
  *
  * @return bool
  */
 public function containsImage(Image $image, DatabaseManager $db)
 {
     return !!$db->connection()->selectOne("SELECT `albumId` FROM `album_images` WHERE `albumId` = ? AND `imageId` = ?", [$this->getId(), $image->getId()]);
 }
Exemple #5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $image = Image::findOrFail($this->argument('imageId'));
     var_dump($image->delete());
 }
 /**
  * @api            {put} /images/{imageId}/image?action=rotate Rotate an Image
  * @apiGroup       Manipulating Images
  * @apiDescription Rotate an image clockwise or counter-clockwise.
  * @apiParam {string=rotate} action Action to perform.
  * @apiParam {int=90,180,270} degrees Degrees to rotate by.
  * @apiParam {string=cw,ccw} [direction=cw] Direction to rotate in (clockwise or counter-clockwise respectively).
  * @apiUse         RequiresEditableImage
  * @apiUse         ImageSuccessResponse
  *
  * @param Image       $image
  * @param FileManager $fileManager
  *
  * @throws Exception
  * @return Response
  */
 protected function rotate(Image $image, FileManager $fileManager)
 {
     $success = false;
     $this->validate($this->request, ['degrees' => 'required|integer|in:90,180,270', 'direction' => 'in:cw,ccw']);
     if ($image->operationInProgress) {
         throw new HttpException(409, "Another operation is currently in progress for this image.");
     }
     $image->operationInProgress = true;
     $image->save();
     $degrees = (int) $this->request->input('degrees');
     $direction = $this->request->has('direction') ? $this->request->input('direction') : 'cw';
     if ($direction === 'cw') {
         $degrees = -$degrees;
     }
     $picture = $fileManager->getPictureForImageFile($image->imageFile);
     $picture->rotate($degrees);
     if ($newImageFile = $fileManager->savePicture($picture)) {
         $image->setImageFile($newImageFile);
         $image->operationInProgress = false;
         $success = $image->save();
     }
     return $this->response(['success' => $success, 'image' => $image->fresh()]);
 }
Exemple #7
0
 /**
  * Returns the Image objects for the imageIds list in the request.
  *
  * @return Image[]
  */
 protected function getMultipleImageInput()
 {
     $this->validate($this->request, ['imageIds' => 'required|string']);
     $imageIds = explode(',', $this->request->input('imageIds'));
     $images = [];
     foreach ($imageIds as $imageId) {
         if ($image = Image::find($imageId)) {
             /** @var Image $image */
             $this->requireEditableImage($image);
         } else {
             throw new NotFoundHttpException("Image {$imageId} does not exist.");
         }
     }
     return $images;
 }