1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-21 13:11:18 +02:00

bugfix in default encoding

This commit is contained in:
Oliver Vogel
2014-05-18 12:45:07 +02:00
parent cce735016e
commit ef57a497c1
2 changed files with 56 additions and 2 deletions

View File

@@ -62,13 +62,18 @@ abstract class AbstractEncoder
$this->result = $this->processPng(); $this->result = $this->processPng();
break; break;
default:
case 'jpg': case 'jpg':
case 'jpeg': case 'jpeg':
case 'image/jpg': case 'image/jpg':
case 'image/jpeg': case 'image/jpeg':
$this->result = $this->processJpeg(); $this->result = $this->processJpeg();
break; break;
default:
throw new \Intervention\Image\Exception\NotSupportedException(
"Writing format ({$format}) is not supported."
);
break;
} }
return $image->setEncoded($this->result); return $image->setEncoded($this->result);
@@ -83,7 +88,7 @@ abstract class AbstractEncoder
{ {
return sprintf('data:%s;base64,%s', return sprintf('data:%s;base64,%s',
$this->image->mime, $this->image->mime,
base64_encode($this->process($this->image, $this->quality)) base64_encode($this->process($this->image, null, $this->quality))
); );
} }

View File

@@ -46,6 +46,31 @@ class EncoderTest extends PHPUnit_Framework_TestCase
$this->assertEquals('image/gif; charset=binary', $this->getMime($encoder->result)); $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() public function testProcessJpegImagick()
{ {
$core = $this->getImagickMock('jpeg'); $core = $this->getImagickMock('jpeg');
@@ -82,6 +107,30 @@ class EncoderTest extends PHPUnit_Framework_TestCase
$this->assertEquals('mock-gif', $encoder->result); $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) public function getImagickMock($type)
{ {
$imagick = Mockery::mock('Imagick'); $imagick = Mockery::mock('Imagick');