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:
@@ -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))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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');
|
||||||
|
Reference in New Issue
Block a user