/** * Constructor * * Instantiate an image file object based on either a pre-existing * image file on disk, or a new image file using the Imagick extension. * * @param string $img * @param int $w * @param int $h * @throws Exception * @return Imagick */ public function __construct($img = null, $w = null, $h = null) { // Check to see if Imagick is installed. if (!self::isInstalled()) { throw new Exception('Error: The Imagick extension must be installed to use the Imagick adapter.'); } // Set the allowed formats $this->setFormats(); parent::__construct($img, $w, $h); // If image exists if (file_exists($this->fullpath) && $this->size > 0) { $this->load($img); // Else, if image does not exists } else { if (null !== $this->width && null !== $this->height) { $this->create($this->width, $this->height, $this->basename); } } // Set a default quality $this->setQuality(80); // Get the extension info $imagickVersion = (new \Imagick())->getVersion(); $versionString = trim(substr($imagickVersion['versionString'], 0, stripos($imagickVersion['versionString'], 'http://'))); $version = substr($versionString, strpos($versionString, ' ') + 1); $version = substr($version, 0, strpos($version, '-')); $this->info = new \ArrayObject(['version' => $version, 'versionString' => $versionString], \ArrayObject::ARRAY_AS_PROPS); }
/** * Constructor * * Instantiate an image file object based on either a pre-existing * image file on disk, or a new image file using the GD extension. * * @param string $img * @param int $w * @param int $h * @throws Exception * @return Gd */ public function __construct($img = null, $w = null, $h = null) { // Check to see if GD is installed. if (!self::isInstalled()) { throw new Exception('Error: The GD library extension must be installed to use the Gd adapter.'); } parent::__construct($img, $w, $h); // If image exists if (file_exists($this->fullpath) && $this->size > 0) { $this->load($img); // Else, if image does not exists } else { if (null !== $this->width && null !== $this->height) { $this->create($this->width, $this->height, $this->basename); } } // Set a default quality $this->setQuality(80); // Get the extension info $gd = gd_info(); $this->info = new \ArrayObject(['version' => $gd['GD Version'], 'freeTypeSupport' => $gd['FreeType Support'], 'freeTypeLinkage' => $gd['FreeType Linkage'], 'gifReadSupport' => $gd['GIF Read Support'], 'gifCreateSupport' => $gd['GIF Create Support'], 'jpegSupport' => $gd['JPEG Support'], 'pngSupport' => $gd['PNG Support'], 'wbmpSupport' => $gd['WBMP Support'], 'xpmSupport' => $gd['XPM Support'], 'xbmSupport' => $gd['XBM Support'], 'japaneseFontSupport' => $gd['JIS-mapped Japanese Font Support']], \ArrayObject::ARRAY_AS_PROPS); }