protected function execute(InputInterface $input, OutputInterface $output)
 {
     $list = new Asset\Image\Thumbnail\Config\Listing();
     $items = $list->load();
     $thumbnails = [];
     foreach ($items as $item) {
         $thumbnails[] = $item->getName();
     }
     $allowedThumbs = [];
     if ($input->getOption("thumbnails")) {
         $allowedThumbs = explode(",", $input->getOption("thumbnails"));
     }
     // get only images
     $conditions = ["type = 'image'"];
     if ($input->getOption("parent")) {
         $parent = Asset::getById($input->getOption("parent"));
         if ($parent instanceof Asset\Folder) {
             $conditions[] = "path LIKE '" . $parent->getRealFullPath() . "/%'";
         } else {
             $this->writeError($input->getOption("parent") . " is not a valid asset folder ID!");
             exit;
         }
     }
     $list = new Asset\Listing();
     $list->setCondition(implode(" AND ", $conditions));
     $total = $list->getTotalCount();
     $perLoop = 10;
     for ($i = 0; $i < ceil($total / $perLoop); $i++) {
         $list->setLimit($perLoop);
         $list->setOffset($i * $perLoop);
         $images = $list->load();
         foreach ($images as $image) {
             foreach ($thumbnails as $thumbnail) {
                 if (empty($allowedThumbs) && !$input->getOption("system") || in_array($thumbnail, $allowedThumbs)) {
                     if ($input->getOption("force")) {
                         $image->clearThumbnail($thumbnail);
                     }
                     $this->output->writeln("generating thumbnail for image: " . $image->getRealFullPath() . " | " . $image->getId() . " | Thumbnail: " . $thumbnail . " : " . formatBytes(memory_get_usage()));
                     $this->output->writeln("generated thumbnail: " . $image->getThumbnail($thumbnail)->getFilesystemPath());
                 }
             }
             if ($input->getOption("system")) {
                 $thumbnail = Asset\Image\Thumbnail\Config::getPreviewConfig();
                 if ($input->getOption("force")) {
                     $image->clearThumbnail($thumbnail->getName());
                 }
                 $this->output->writeln("generating thumbnail for image: " . $image->getRealFullPath() . " | " . $image->getId() . " | Thumbnail: System Preview (tree) : " . formatBytes(memory_get_usage()));
                 $this->output->writeln("generated thumbnail: " . $image->getThumbnail($thumbnail)->getFilesystemPath());
             }
         }
         \Pimcore::collectGarbage();
     }
 }
Example #2
0
 /**
  * Returns a list of all image thumbnails.
  */
 public function imageThumbnailsAction()
 {
     $this->checkUserPermission("thumbnails");
     $thumbnails = [];
     $list = new Asset\Image\Thumbnail\Config\Listing();
     $items = $list->load();
     foreach ($items as $item) {
         $thumbnails[] = ["id" => $item->getName(), "text" => $item->getName()];
     }
     $this->encoder->encode(["success" => true, "data" => $thumbnails]);
 }
Example #3
0
 public function thumbnailTreeAction()
 {
     $this->checkPermission("thumbnails");
     $thumbnails = [];
     $list = new Asset\Image\Thumbnail\Config\Listing();
     $items = $list->load();
     foreach ($items as $item) {
         $thumbnails[] = ["id" => $item->getName(), "text" => $item->getName()];
     }
     $this->_helper->json($thumbnails);
 }