/** * Open the image. * @param string $filename * @param boolean $throwErrors * @throws InvalidParamException * @throws \ErrorException */ public function __construct($filename, $throwErrors = true) { static $isLoaded; if (!isset($isLoaded)) { $isLoaded = self::isLoaded(); } parent::__construct($filename, $throwErrors); $this->im = new \Imagick(); $this->im->readImage($this->filename); if (!$this->im->getImageAlphaChannel()) { $this->im->setImageAlphaChannel(\Imagick::ALPHACHANNEL_SET); } }
/** * Read image. * @param string $filename * @param boolean $throwErrors * @throws InvalidParamException * @throws \ErrorException */ public function __construct($filename, $throwErrors = true) { static $isLoaded; if (!isset($isLoaded)) { $isLoaded = self::isLoaded(); } parent::__construct($filename, $throwErrors); $create_func = 'imagecreatefrom' . $this->getFormat(); $this->image = $create_func($this->filename); if (!$this->image) { $this->error = sprintf('Bad image format: "%s"', $this->filename); if ($throwErrors) { throw new InvalidParamException($this->error); } } else { imagesavealpha($this->image, true); } }