Pimcore\Image\Adapter\Imagick::load PHP Method

load() public method

public load ( $imagePath, array $options = [] )
$imagePath
$options array
    public function load($imagePath, $options = [])
    {
        // support image URLs
        if (preg_match("@^https?://@", $imagePath)) {
            $tmpFilename = "imagick_auto_download_" . md5($imagePath) . "." . File::getFileExtension($imagePath);
            $tmpFilePath = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/" . $tmpFilename;
            $this->tmpFiles[] = $tmpFilePath;
            File::put($tmpFilePath, \Pimcore\Tool::getHttpData($imagePath));
            $imagePath = $tmpFilePath;
        }
        if (!stream_is_local($imagePath)) {
            // imagick is only able to deal with local files
            // if your're using custom stream wrappers this wouldn't work, so we create a temp. local copy
            $tmpFilePath = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/imagick-tmp-" . uniqid() . "." . File::getFileExtension($imagePath);
            copy($imagePath, $tmpFilePath);
            $imagePath = $tmpFilePath;
            $this->tmpFiles[] = $imagePath;
        }
        if ($this->resource) {
            unset($this->resource);
            $this->resource = null;
        }
        try {
            $i = new \Imagick();
            $this->imagePath = $imagePath;
            if (!$this->isPreserveColor() && method_exists($i, "setcolorspace")) {
                $i->setcolorspace(\Imagick::COLORSPACE_SRGB);
            }
            if (!$this->isPreserveColor() && $this->isVectorGraphic($imagePath)) {
                // only for vector graphics
                // the below causes problems with PSDs when target format is PNG32 (nobody knows why ;-))
                $i->setBackgroundColor(new \ImagickPixel('transparent'));
            }
            if (isset($options["resolution"])) {
                // set the resolution to 2000x2000 for known vector formats
                // otherwise this will cause problems with eg. cropPercent in the image editable (select specific area)
                // maybe there's a better solution but for now this fixes the problem
                $i->setResolution($options["resolution"]["x"], $options["resolution"]["y"]);
            }
            $imagePathLoad = $imagePath;
            if (!defined("HHVM_VERSION")) {
                $imagePathLoad .= "[0]";
                // not supported by HHVM implementation - selects the first layer/page in layered/pages file formats
            }
            if (!$i->readImage($imagePathLoad) || !filesize($imagePath)) {
                return false;
            }
            $this->resource = $i;
            // this is because of HHVM which has problems with $this->resource->readImage();
            // set dimensions
            $dimensions = $this->getDimensions();
            $this->setWidth($dimensions["width"]);
            $this->setHeight($dimensions["height"]);
            // check if image can have alpha channel
            if (!$this->reinitializing) {
                $alphaChannel = $i->getImageAlphaChannel();
                if ($alphaChannel) {
                    $this->setIsAlphaPossible(true);
                }
            }
            if (!$this->isPreserveColor()) {
                $this->setColorspaceToRGB();
            }
        } catch (\Exception $e) {
            Logger::error("Unable to load image: " . $imagePath);
            Logger::error($e);
            return false;
        }
        $this->setModified(false);
        return $this;
    }