diff --git a/src/Intervention/Image/AbstractEncoder.php b/src/Intervention/Image/AbstractEncoder.php index dc264005..cffb5f53 100644 --- a/src/Intervention/Image/AbstractEncoder.php +++ b/src/Intervention/Image/AbstractEncoder.php @@ -25,6 +25,13 @@ abstract class AbstractEncoder */ abstract protected function processGif(); + /** + * Processes and returns encoded image as TIFF string + * + * @return string + */ + abstract protected function processTiff(); + /** * Buffer of encode result data * @@ -69,16 +76,15 @@ abstract class AbstractEncoder $this->result = $this->processJpeg(); break; + case 'tif': case 'tiff': case 'image/tiff': - if (method_exists($this, 'processTiff')) { - $this->result = $this->processTiff(); - break; - } - //fall through + $this->result = $this->processTiff(); + break; + default: throw new \Intervention\Image\Exception\NotSupportedException( - "Writing format ({$format}) is not supported." + "Encoding format ({$format}) is not supported." ); break; } diff --git a/src/Intervention/Image/Gd/Encoder.php b/src/Intervention/Image/Gd/Encoder.php index 9f1582ee..96989744 100644 --- a/src/Intervention/Image/Gd/Encoder.php +++ b/src/Intervention/Image/Gd/Encoder.php @@ -54,4 +54,16 @@ class Encoder extends \Intervention\Image\AbstractEncoder return $buffer; } + + /** + * Processes and returns encoded image as TIFF string + * + * @return string + */ + protected function processTiff() + { + throw new \Intervention\Image\Exception\NotSupportedException( + "TIFF format is not supported by Gd Driver." + ); + } } diff --git a/tests/EncoderTest.php b/tests/EncoderTest.php index a9220391..fbffca2b 100644 --- a/tests/EncoderTest.php +++ b/tests/EncoderTest.php @@ -46,6 +46,18 @@ class EncoderTest extends PHPUnit_Framework_TestCase $this->assertEquals('image/gif; charset=binary', $this->getMime($encoder->result)); } + /** + * @expectedException \Intervention\Image\Exception\NotSupportedException + */ + public function testProcessTiffGd() + { + $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); + $encoder = new GdEncoder; + $image = Mockery::mock('\Intervention\Image\Image'); + $img = $encoder->process($image, 'tif', 90); + $this->assertInstanceOf('Intervention\Image\Image', $img); + } + public function testProcessUnknownWithMimeGd() { $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); @@ -107,6 +119,18 @@ class EncoderTest extends PHPUnit_Framework_TestCase $this->assertEquals('mock-gif', $encoder->result); } + public function testProcessTiffImagick() + { + $core = $this->getImagickMock('tiff'); + $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, 'tiff', 90); + $this->assertInstanceOf('Intervention\Image\Image', $img); + $this->assertEquals('mock-tiff', $encoder->result); + } + public function testProcessUnknownWithMimeImagick() { $core = $this->getImagickMock('jpeg');