setFormat() публичный Метод

public setFormat ( string $format )
$format string
Пример #1
0
 public function downloadImageThumbnailAction()
 {
     $image = Asset\Image::getById($this->getParam("id"));
     $config = null;
     if ($this->getParam("config")) {
         $config = \Zend_Json::decode($this->getParam("config"));
     } elseif ($this->getParam("type")) {
         $predefined = ["web" => ["resize_mode" => "scaleByWidth", "width" => 3500, "dpi" => 72, "format" => "JPEG", "quality" => 85], "print" => ["resize_mode" => "scaleByWidth", "width" => 6000, "dpi" => 300, "format" => "JPEG", "quality" => 95], "office" => ["resize_mode" => "scaleByWidth", "width" => 1190, "dpi" => 144, "format" => "JPEG", "quality" => 90]];
         $config = $predefined[$this->getParam("type")];
     }
     if ($config) {
         $thumbnailConfig = new Asset\Image\Thumbnail\Config();
         $thumbnailConfig->setName("pimcore-download-" . $image->getId() . "-" . md5($this->getParam("config")));
         if ($config["resize_mode"] == "scaleByWidth") {
             $thumbnailConfig->addItem("scaleByWidth", ["width" => $config["width"]]);
         } elseif ($config["resize_mode"] == "scaleByHeight") {
             $thumbnailConfig->addItem("scaleByHeight", ["height" => $config["height"]]);
         } else {
             $thumbnailConfig->addItem("resize", ["width" => $config["width"], "height" => $config["height"]]);
         }
         $thumbnailConfig->setQuality($config["quality"]);
         $thumbnailConfig->setFormat($config["format"]);
         if ($thumbnailConfig->getFormat() == "JPEG") {
             $thumbnailConfig->setPreserveMetaData(true);
             $thumbnailConfig->setPreserveColor(true);
         }
         $thumbnail = $image->getThumbnail($thumbnailConfig);
         $thumbnailFile = $thumbnail->getFileSystemPath();
         $exiftool = \Pimcore\Tool\Console::getExecutable("exiftool");
         if ($thumbnailConfig->getFormat() == "JPEG" && $exiftool && isset($config["dpi"]) && $config["dpi"]) {
             \Pimcore\Tool\Console::exec($exiftool . " -overwrite_original -xresolution=" . $config["dpi"] . " -yresolution=" . $config["dpi"] . " -resolutionunit=inches " . escapeshellarg($thumbnailFile));
         }
         $downloadFilename = str_replace("." . File::getFileExtension($image->getFilename()), "." . $thumbnail->getFileExtension(), $image->getFilename());
         $downloadFilename = strtolower($downloadFilename);
         header('Content-Disposition: attachment; filename="' . $downloadFilename . '"');
         header("Content-Type: " . $thumbnail->getMimeType(), true);
         // we have to clear the stat cache here, otherwise filesize() would return the wrong value
         // the reason is that exiftool modifies the file's size, but PHP doesn't know anything about that
         clearstatcache();
         header("Content-Length: " . filesize($thumbnailFile), true);
         $this->sendThumbnailCacheHeaders();
         while (@ob_end_flush()) {
         }
         flush();
         readfile($thumbnailFile);
         @unlink($thumbnailFile);
         exit;
     }
 }
Пример #2
0
 /**
  * how many frames, delay in seconds between frames, pimcore thumbnail configuration
  *
  * @param int $frames
  * @param int $delay
  * @param null $thumbnail
  * @return string
  */
 public function getPreviewAnimatedGif($frames = 10, $delay = 200, $thumbnail = null)
 {
     if (!$frames) {
         $frames = 10;
     }
     if (!$delay) {
         $delay = 200;
         // no clue which unit this has ;-)
     }
     $thumbnailUniqueId = md5(serialize([$thumbnail, $frames, $delay]));
     $animGifPath = PIMCORE_TEMPORARY_DIRECTORY . "/video-image-cache/video_" . $this->getId() . "_" . $thumbnailUniqueId . ".gif";
     if (!is_file($animGifPath)) {
         $duration = $this->getDuration();
         $sampleRate = floor($duration / $frames);
         $thumbnails = [];
         $delays = [];
         $thumbnailConfig = $this->getImageThumbnailConfig($thumbnail);
         if (!$thumbnailConfig) {
             $thumbnailConfig = new Image\Thumbnail\Config();
         }
         $thumbnailConfig->setFormat("GIF");
         for ($i = 0; $i <= $frames; $i++) {
             $frameImage = $this->getImageThumbnail($thumbnailConfig, $i * $sampleRate);
             $frameImage = PIMCORE_DOCUMENT_ROOT . $frameImage;
             if (preg_match("/\\.gif\$/", $frameImage) && filesize($frameImage) > 10) {
                 // check if the image is correct and not a "not supported" placeholder
                 $thumbnails[] = $frameImage;
                 $delays[] = $delay;
             }
         }
         try {
             $animator = new \Pimcore\Image\GifAnimator($thumbnails, $delays, 0, 2, 255, 255, 255, "url");
             $animGifContent = $animator->GetAnimation();
         } catch (\Exception $e) {
             \Logger::error($e);
             $animGifContent = file_get_contents($thumbnails[0]);
         }
         File::put($animGifPath, $animGifContent);
     }
     $animGifPath = preg_replace("@^" . preg_quote(PIMCORE_DOCUMENT_ROOT, "@") . "@", "", $animGifPath);
     return $animGifPath;
 }