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(); } }
/** * @return void */ protected function update() { // only do this if the file exists and contains data if ($this->getDataChanged() || !$this->getCustomSetting("imageDimensionsCalculated")) { try { // save the current data into a tmp file to calculate the dimensions, otherwise updates wouldn't be updated // because the file is written in parent::update(); $tmpFile = $this->getTemporaryFile(); $dimensions = $this->getDimensions($tmpFile, true); unlink($tmpFile); if ($dimensions && $dimensions["width"]) { $this->setCustomSetting("imageWidth", $dimensions["width"]); $this->setCustomSetting("imageHeight", $dimensions["height"]); } } catch (\Exception $e) { Logger::error("Problem getting the dimensions of the image with ID " . $this->getId()); } // this is to be downward compatible so that the controller can check if the dimensions are already calculated // and also to just do the calculation once, because the calculation can fail, an then the controller tries to // calculate the dimensions on every request an also will create a version, ... $this->setCustomSetting("imageDimensionsCalculated", true); } parent::update(); $this->clearThumbnails(); // now directly create "system" thumbnails (eg. for the tree, ...) if ($this->getDataChanged()) { try { $path = $this->getThumbnail(Image\Thumbnail\Config::getPreviewConfig())->getFileSystemPath(); // set the modification time of the thumbnail to the same time from the asset // so that the thumbnail check doesn't fail in Asset\Image\Thumbnail\Processor::process(); // we need the @ in front of touch because of some stream wrapper (eg. s3) which don't support touch() @touch($path, $this->getModificationDate()); } catch (\Exception $e) { Logger::error("Problem while creating system-thumbnails for image " . $this->getRealFullPath()); Logger::error($e); } } }
} } $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) && !$opts->getOption("system") || in_array($thumbnail, $allowedThumbs)) { if ($opts->getOption("force")) { $image->clearThumbnail($thumbnail); } echo "generating thumbnail for image: " . $image->getFullpath() . " | " . $image->getId() . " | Thumbnail: " . $thumbnail . " : " . formatBytes(memory_get_usage()) . " \n"; echo "generated thumbnail: " . $image->getThumbnail($thumbnail) . "\n"; } } if ($opts->getOption("system")) { $thumbnail = Asset\Image\Thumbnail\Config::getPreviewConfig(); if ($opts->getOption("force")) { $image->clearThumbnail($thumbnail->getName()); } echo "generating thumbnail for image: " . $image->getFullpath() . " | " . $image->getId() . " | Thumbnail: System Preview (tree) : " . formatBytes(memory_get_usage()) . " \n"; echo "generated thumbnail: " . $image->getThumbnail($thumbnail) . "\n"; } } \Pimcore::collectGarbage(); }
public function getDocumentThumbnailAction() { $document = Asset::getById(intval($this->getParam("id"))); $thumbnail = Asset\Image\Thumbnail\Config::getByAutoDetect($this->getAllParams()); $format = strtolower($thumbnail->getFormat()); if ($format == "source") { $thumbnail->setFormat("jpeg"); // default format for documents is JPEG not PNG (=too big) } if ($this->getParam("treepreview")) { $thumbnail = Asset\Image\Thumbnail\Config::getPreviewConfig(); } $page = 1; if (is_numeric($this->getParam("page"))) { $page = (int) $this->getParam("page"); } $thumbnailFile = PIMCORE_DOCUMENT_ROOT . $document->getImageThumbnail($thumbnail, $page); $format = "png"; header("Content-type: image/" . $format, true); header("Content-Length: " . filesize($thumbnailFile), true); $this->sendThumbnailCacheHeaders(); while (@ob_end_flush()) { } flush(); readfile($thumbnailFile); exit; }