diff --git a/src/Intervention/Image/AbstractEncoder.php b/src/Intervention/Image/AbstractEncoder.php index c21fb8d2..9cbf7dc4 100644 --- a/src/Intervention/Image/AbstractEncoder.php +++ b/src/Intervention/Image/AbstractEncoder.php @@ -67,6 +67,13 @@ abstract class AbstractEncoder */ abstract protected function processBmp(); + /** + * Processes and returns encoded image as ICO string + * + * @return string + */ + abstract protected function processIco(); + /** * Process a given image * @@ -126,6 +133,17 @@ abstract class AbstractEncoder case 'image/x-xbitmap': $this->result = $this->processBmp(); break; + + case 'ico': + case 'image/x-icon': + case 'image/vnd.microsoft.icon': + $this->result = $this->processIco(); + break; + + case 'psd': + case 'image/vnd.adobe.photoshop': + $this->result = $this->processPsd(); + break; default: throw new \Intervention\Image\Exception\NotSupportedException( diff --git a/src/Intervention/Image/Gd/Encoder.php b/src/Intervention/Image/Gd/Encoder.php index cafc43b5..97a2c271 100644 --- a/src/Intervention/Image/Gd/Encoder.php +++ b/src/Intervention/Image/Gd/Encoder.php @@ -78,4 +78,28 @@ class Encoder extends \Intervention\Image\AbstractEncoder "BMP format is not supported by Gd Driver." ); } + + /** + * Processes and returns encoded image as ICO string + * + * @return string + */ + protected function processIco() + { + throw new \Intervention\Image\Exception\NotSupportedException( + "ICO format is not supported by Gd Driver." + ); + } + + /** + * Processes and returns encoded image as PSD string + * + * @return string + */ + protected function processPsd() + { + throw new \Intervention\Image\Exception\NotSupportedException( + "PSD format is not supported by Gd Driver." + ); + } } diff --git a/src/Intervention/Image/Imagick/Encoder.php b/src/Intervention/Image/Imagick/Encoder.php index 3d5f2b01..2d6c235f 100644 --- a/src/Intervention/Image/Imagick/Encoder.php +++ b/src/Intervention/Image/Imagick/Encoder.php @@ -105,4 +105,42 @@ class Encoder extends \Intervention\Image\AbstractEncoder return $imagick->getImagesBlob(); } + + /** + * Processes and returns encoded image as ICO string + * + * @return string + */ + protected function processIco() + { + $format = 'ico'; + $compression = \Imagick::COMPRESSION_UNDEFINED; + + $imagick = $this->image->getCore(); + $imagick->setFormat($format); + $imagick->setImageFormat($format); + $imagick->setCompression($compression); + $imagick->setImageCompression($compression); + + return $imagick->getImagesBlob(); + } + + /** + * Processes and returns encoded image as PSD string + * + * @return string + */ + protected function processPsd() + { + $format = 'psd'; + $compression = \Imagick::COMPRESSION_UNDEFINED; + + $imagick = $this->image->getCore(); + $imagick->setFormat($format); + $imagick->setImageFormat($format); + $imagick->setCompression($compression); + $imagick->setImageCompression($compression); + + return $imagick->getImagesBlob(); + } } diff --git a/tests/EncoderTest.php b/tests/EncoderTest.php index bb3db3da..0b7eba8b 100644 --- a/tests/EncoderTest.php +++ b/tests/EncoderTest.php @@ -58,6 +58,42 @@ class EncoderTest extends PHPUnit_Framework_TestCase $this->assertInstanceOf('Intervention\Image\Image', $img); } + /** + * @expectedException \Intervention\Image\Exception\NotSupportedException + */ + public function testProcessBmpGd() + { + $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); + $encoder = new GdEncoder; + $image = Mockery::mock('\Intervention\Image\Image'); + $img = $encoder->process($image, 'bmp', 90); + $this->assertInstanceOf('Intervention\Image\Image', $img); + } + + /** + * @expectedException \Intervention\Image\Exception\NotSupportedException + */ + public function testProcessIcoGd() + { + $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); + $encoder = new GdEncoder; + $image = Mockery::mock('\Intervention\Image\Image'); + $img = $encoder->process($image, 'ico', 90); + $this->assertInstanceOf('Intervention\Image\Image', $img); + } + + /** + * @expectedException \Intervention\Image\Exception\NotSupportedException + */ + public function testProcessPsdGd() + { + $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); + $encoder = new GdEncoder; + $image = Mockery::mock('\Intervention\Image\Image'); + $img = $encoder->process($image, 'psd', 90); + $this->assertInstanceOf('Intervention\Image\Image', $img); + } + public function testProcessUnknownWithMimeGd() { $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); @@ -131,6 +167,42 @@ class EncoderTest extends PHPUnit_Framework_TestCase $this->assertEquals('mock-tiff', $encoder->result); } + public function testProcessBmpImagick() + { + $core = $this->getImagickMock('bmp'); + $encoder = new ImagickEncoder; + $image = Mockery::mock('\Intervention\Image\Image'); + $image->shouldReceive('getCore')->once()->andReturn($core); + $image->shouldReceive('setEncoded')->once()->andReturn($image); + $img = $encoder->process($image, 'bmp', 90); + $this->assertInstanceOf('Intervention\Image\Image', $img); + $this->assertEquals('mock-bmp', $encoder->result); + } + + public function testProcessIcoImagick() + { + $core = $this->getImagickMock('ico'); + $encoder = new ImagickEncoder; + $image = Mockery::mock('\Intervention\Image\Image'); + $image->shouldReceive('getCore')->once()->andReturn($core); + $image->shouldReceive('setEncoded')->once()->andReturn($image); + $img = $encoder->process($image, 'ico', 90); + $this->assertInstanceOf('Intervention\Image\Image', $img); + $this->assertEquals('mock-ico', $encoder->result); + } + + public function testProcessPsdImagick() + { + $core = $this->getImagickMock('psd'); + $encoder = new ImagickEncoder; + $image = Mockery::mock('\Intervention\Image\Image'); + $image->shouldReceive('getCore')->once()->andReturn($core); + $image->shouldReceive('setEncoded')->once()->andReturn($image); + $img = $encoder->process($image, 'psd', 90); + $this->assertInstanceOf('Intervention\Image\Image', $img); + $this->assertEquals('mock-psd', $encoder->result); + } + public function testProcessUnknownWithMimeImagick() { $core = $this->getImagickMock('jpeg');