protected function execute(InputInterface $input, OutputInterface $output)
 {
     // get all thumbnails
     $dir = Asset\Image\Thumbnail\Config::getWorkingDir();
     $thumbnails = array();
     $files = scandir($dir);
     foreach ($files as $file) {
         if (strpos($file, ".xml")) {
             $thumbnails[] = str_replace(".xml", "", $file);
         }
     }
     $allowedThumbs = array();
     if ($input->getOption("thumbnails")) {
         $allowedThumbs = explode(",", $input->getOption("thumbnails"));
     }
     // get only images
     $conditions = array("type = 'image'");
     if ($input->getOption("parent")) {
         $parent = Asset::getById($input->getOption("parent"));
         if ($parent instanceof Asset\Folder) {
             $conditions[] = "path LIKE '" . $parent->getFullPath() . "/%'";
         } 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->getFullpath() . " | " . $image->getId() . " | Thumbnail: " . $thumbnail . " : " . formatBytes(memory_get_usage()));
                     $this->output->writeln("generated thumbnail: " . $image->getThumbnail($thumbnail));
                 }
             }
             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->getFullpath() . " | " . $image->getId() . " | Thumbnail: System Preview (tree) : " . formatBytes(memory_get_usage()));
                 $this->output->writeln("generated thumbnail: " . $image->getThumbnail($thumbnail));
             }
         }
         \Pimcore::collectGarbage();
     }
 }
Example #2
0
    echo $e->getMessage();
}
// display help message
if ($opts->getOption("help")) {
    echo $opts->getUsageMessage();
    exit;
}
if ($opts->getOption("verbose")) {
    $logger = new \Monolog\Logger('core');
    $logger->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout'));
    \Logger::addLogger($logger);
    // set all priorities
    \Logger::setVerbosePriorities();
}
// get all thumbnails
$dir = Asset\Image\Thumbnail\Config::getWorkingDir();
$thumbnails = array();
$files = scandir($dir);
foreach ($files as $file) {
    if (strpos($file, ".xml")) {
        $thumbnails[] = str_replace(".xml", "", $file);
    }
}
$allowedThumbs = array();
if ($opts->getOption("thumbnails")) {
    $allowedThumbs = explode(",", $opts->getOption("thumbnails"));
}
// get only images
$conditions = array("type = 'image'");
if ($opts->getOption("parent")) {
    $parent = Asset::getById($opts->getOption("parent"));
 /**
  * Returns a list of all image thumbnails.
  */
 public function imageThumbnailsAction()
 {
     $this->checkUserPermission("thumbnails");
     $dir = Asset\Image\Thumbnail\Config::getWorkingDir();
     $pipelines = array();
     $files = scandir($dir);
     foreach ($files as $file) {
         if (strpos($file, ".xml")) {
             $name = str_replace(".xml", "", $file);
             $pipelines[] = array("id" => $name, "text" => $name);
         }
     }
     $this->encoder->encode(array("success" => true, "data" => $pipelines));
 }
 public function thumbnailTreeAction()
 {
     $this->checkPermission("thumbnails");
     $dir = Asset\Image\Thumbnail\Config::getWorkingDir();
     $pipelines = array();
     $files = scandir($dir);
     foreach ($files as $file) {
         if (strpos($file, ".xml")) {
             $name = str_replace(".xml", "", $file);
             $pipelines[] = array("id" => $name, "text" => $name);
         }
     }
     $this->_helper->json($pipelines);
 }