imageHelper = $imageHelper; $this->themeHelper = $themeHelper; } /** * Execute the console command. * * @return mixed */ public function handle() { $id = intval($this->argument('id')); if ($this->option('album')) { $this->handleAlbum($id); } else { $this->handlePhoto($id); } } private function handleAlbum($id) { $album = Album::where('id', $id)->first(); if (is_null($album)) { throw new \Exception(sprintf('The album with ID %d could not be found', $id)); } /** @var Photo $photo */ foreach ($album->photos as $photo) { $this->regenerateThumbnailsForPhoto($album, $photo); } } private function handlePhoto($id) { $photo = Photo::where('id', $id)->first(); if (is_null($photo)) { throw new \Exception(sprintf('The photo with ID %d could not be found', $id)); } /** @var Album $album */ $album = $photo->album; $this->regenerateThumbnailsForPhoto($album, $photo); } private function regenerateThumbnailsForPhoto(Album $album, Photo $photo) { $albumSource = $album->getAlbumSource(); $originalPhotoResource = $this->imageHelper->openImage($albumSource->getPathToPhoto($album, $photo), $imageInfo); if (!is_resource($originalPhotoResource)) { throw new \Exception(sprintf('The original image for photo ID %d could not be found', $id)); } $this->output->writeln(sprintf('Generating thumbnails for "%s"...', $photo->file_name)); $themeInfo = $this->themeHelper->info(); $thumbnailsRequired = $themeInfo['thumbnails']; /** @var mixed $thumbnail */ foreach ($thumbnailsRequired as $thumbnail) { $generatedThumbnailPath = $this->imageHelper->generateThumbnail($originalPhotoResource, $photo, $thumbnail); $albumSource->saveThumbnail($album, $photo, $thumbnail, $generatedThumbnailPath); $this->output->writeln(sprintf('Thumbnail \'%s\' (%dx%d) created', $thumbnail['name'], $thumbnail['width'], $thumbnail['height'])); } } }