Admin_AssetController::getImageThumbnailAction PHP Метод

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

    public function getImageThumbnailAction()
    {
        $fileinfo = $this->getParam("fileinfo");
        $image = Asset\Image::getById(intval($this->getParam("id")));
        $thumbnail = null;
        if ($this->getParam("thumbnail")) {
            $thumbnail = $image->getThumbnailConfig($this->getParam("thumbnail"));
        }
        if (!$thumbnail) {
            if ($this->getParam("config")) {
                $thumbnail = $image->getThumbnailConfig(\Zend_Json::decode($this->getParam("config")));
            } else {
                $thumbnail = $image->getThumbnailConfig($this->getAllParams());
            }
        } else {
            // no high-res images in admin mode (editmode)
            // this is mostly because of the document's image editable, which doesn't know anything about the thumbnail
            // configuration, so the dimensions would be incorrect (double the size)
            $thumbnail->setHighResolution(1);
        }
        $format = strtolower($thumbnail->getFormat());
        if ($format == "source" || $format == "print") {
            $thumbnail->setFormat("PNG");
        }
        if ($this->getParam("treepreview")) {
            $thumbnail = Asset\Image\Thumbnail\Config::getPreviewConfig();
        }
        if ($this->getParam("cropPercent")) {
            $thumbnail->addItemAt(0, "cropPercent", ["width" => $this->getParam("cropWidth"), "height" => $this->getParam("cropHeight"), "y" => $this->getParam("cropTop"), "x" => $this->getParam("cropLeft")]);
            $hash = md5(Tool\Serialize::serialize($this->getAllParams()));
            $thumbnail->setName($thumbnail->getName() . "_auto_" . $hash);
        }
        $thumbnail = $image->getThumbnail($thumbnail);
        if ($fileinfo) {
            $this->_helper->json(["width" => $thumbnail->getWidth(), "height" => $thumbnail->getHeight()]);
        }
        $thumbnailFile = $thumbnail->getFileSystemPath();
        header("Content-Type: " . $thumbnail->getMimeType(), true);
        header("Access-Control-Allow-Origin: *");
        // for Aviary.Feather (Adobe Creative SDK)
        header("Content-Length: " . filesize($thumbnailFile), true);
        $this->sendThumbnailCacheHeaders();
        while (@ob_end_flush()) {
        }
        flush();
        readfile($thumbnailFile);
        exit;
    }