diff --git a/src/Intervention/Image/AbstractEncoder.php b/src/Intervention/Image/AbstractEncoder.php index 66162a81..0b4e0638 100644 --- a/src/Intervention/Image/AbstractEncoder.php +++ b/src/Intervention/Image/AbstractEncoder.php @@ -62,13 +62,18 @@ abstract class AbstractEncoder $this->result = $this->processPng(); break; - default: case 'jpg': case 'jpeg': case 'image/jpg': case 'image/jpeg': $this->result = $this->processJpeg(); break; + + default: + throw new \Intervention\Image\Exception\NotSupportedException( + "Writing format ({$format}) is not supported." + ); + break; } return $image->setEncoded($this->result); @@ -83,7 +88,7 @@ abstract class AbstractEncoder { return sprintf('data:%s;base64,%s', $this->image->mime, - base64_encode($this->process($this->image, $this->quality)) + base64_encode($this->process($this->image, null, $this->quality)) ); } diff --git a/tests/EncoderTest.php b/tests/EncoderTest.php index ac10c874..06de64f7 100644 --- a/tests/EncoderTest.php +++ b/tests/EncoderTest.php @@ -46,6 +46,31 @@ class EncoderTest extends PHPUnit_Framework_TestCase $this->assertEquals('image/gif; charset=binary', $this->getMime($encoder->result)); } + public function testProcessUnknownWithMimeGd() + { + $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); + $encoder = new GdEncoder; + $image = Mockery::mock('\Intervention\Image\Image'); + $image->mime = 'image/jpeg'; + $image->shouldReceive('getCore')->once()->andReturn($core); + $image->shouldReceive('setEncoded')->once()->andReturn($image); + $img = $encoder->process($image, null); + $this->assertInstanceOf('Intervention\Image\Image', $img); + $this->assertEquals('image/jpeg; charset=binary', $this->getMime($encoder->result)); + } + + /** + * @expectedException \Intervention\Image\Exception\NotSupportedException + */ + public function testProcessUnknownGd() + { + $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); + $encoder = new GdEncoder; + $image = Mockery::mock('\Intervention\Image\Image'); + $img = $encoder->process($image, null); + $this->assertInstanceOf('Intervention\Image\Image', $img); + } + public function testProcessJpegImagick() { $core = $this->getImagickMock('jpeg'); @@ -82,6 +107,30 @@ class EncoderTest extends PHPUnit_Framework_TestCase $this->assertEquals('mock-gif', $encoder->result); } + public function testProcessUnknownWithMimeImagick() + { + $core = $this->getImagickMock('jpeg'); + $encoder = new ImagickEncoder; + $image = Mockery::mock('\Intervention\Image\Image'); + $image->mime = 'image/jpeg'; + $image->shouldReceive('getCore')->once()->andReturn($core); + $image->shouldReceive('setEncoded')->once()->andReturn($image); + $img = $encoder->process($image, null); + $this->assertInstanceOf('Intervention\Image\Image', $img); + $this->assertEquals('mock-jpeg', $encoder->result); + } + + /** + * @expectedException \Intervention\Image\Exception\NotSupportedException + */ + public function testProcessUnknownImagick() + { + $core = Mockery::mock('Imagick'); + $encoder = new ImagickEncoder; + $image = Mockery::mock('\Intervention\Image\Image'); + $img = $encoder->process($image, null); + } + public function getImagickMock($type) { $imagick = Mockery::mock('Imagick');