/**
* @param $imagePath
* @param array $options
* @return $this|bool|self
*/
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 ($this->resource) {
unset($this->resource);
$this->resource = null;
}
try {
$i = new \Imagick();
$this->imagePath = $imagePath;
if (method_exists($i, "setcolorspace")) {
$i->setcolorspace(\Imagick::COLORSPACE_SRGB);
}
$i->setBackgroundColor(new \ImagickPixel('transparent'));
//set .png transparent (print)
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);
}
}
$this->setColorspaceToRGB();
} catch (\Exception $e) {
\Logger::error("Unable to load image: " . $imagePath);
\Logger::error($e);
return false;
}
$this->setModified(false);
return $this;
}