File indexing completed on 2025-01-26 05:29:15
0001 <?php 0002 0003 namespace Intervention\Image\Imagick; 0004 0005 class Driver extends \Intervention\Image\AbstractDriver 0006 { 0007 /** 0008 * Creates new instance of driver 0009 * 0010 * @param Decoder $decoder 0011 * @param Encoder $encoder 0012 */ 0013 public function __construct(Decoder $decoder = null, Encoder $encoder = null) 0014 { 0015 if ( ! $this->coreAvailable()) { 0016 throw new \Intervention\Image\Exception\NotSupportedException( 0017 "ImageMagick module not available with this PHP installation." 0018 ); 0019 } 0020 0021 $this->decoder = $decoder ? $decoder : new Decoder; 0022 $this->encoder = $encoder ? $encoder : new Encoder; 0023 } 0024 0025 /** 0026 * Creates new image instance 0027 * 0028 * @param int $width 0029 * @param int $height 0030 * @param mixed $background 0031 * @return \Intervention\Image\Image 0032 */ 0033 public function newImage($width, $height, $background = null) 0034 { 0035 $background = new Color($background); 0036 0037 // create empty core 0038 $core = new \Imagick; 0039 $core->newImage($width, $height, $background->getPixel(), 'png'); 0040 $core->setType(\Imagick::IMGTYPE_UNDEFINED); 0041 $core->setImageType(\Imagick::IMGTYPE_UNDEFINED); 0042 $core->setColorspace(\Imagick::COLORSPACE_UNDEFINED); 0043 0044 // build image 0045 $image = new \Intervention\Image\Image(new static, $core); 0046 0047 return $image; 0048 } 0049 0050 /** 0051 * Reads given string into color object 0052 * 0053 * @param string $value 0054 * @return AbstractColor 0055 */ 0056 public function parseColor($value) 0057 { 0058 return new Color($value); 0059 } 0060 0061 /** 0062 * Checks if core module installation is available 0063 * 0064 * @return boolean 0065 */ 0066 protected function coreAvailable() 0067 { 0068 return (extension_loaded('imagick') && class_exists('Imagick')); 0069 } 0070 }