mirror of
https://github.com/Intervention/image.git
synced 2025-09-02 18:32:56 +02:00
@@ -55,9 +55,25 @@ class Decoder extends \Intervention\Image\AbstractDecoder
|
||||
$core = @imagecreatefromwebp($path);
|
||||
break;
|
||||
|
||||
case 'image/bmp':
|
||||
case 'image/ms-bmp':
|
||||
case 'image/x-bitmap':
|
||||
case 'image/x-bmp':
|
||||
case 'image/x-ms-bmp':
|
||||
case 'image/x-win-bitmap':
|
||||
case 'image/x-windows-bmp':
|
||||
case 'image/x-xbitmap':
|
||||
if (! function_exists('imagecreatefrombmp')) {
|
||||
throw new NotReadableException(
|
||||
"Unsupported image type. GD/PHP installation does not support BMP format."
|
||||
);
|
||||
}
|
||||
$core = @imagecreatefrombmp($path);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotReadableException(
|
||||
sprintf("Unsupported image type %s. GD driver is only able to decode JPG, PNG, GIF or WebP files.", strtolower($mime))
|
||||
sprintf("Unsupported image type %s. GD driver is only able to decode JPG, PNG, GIF, BMP or WebP files.", strtolower($mime))
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -96,9 +96,19 @@ class Encoder extends \Intervention\Image\AbstractEncoder
|
||||
*/
|
||||
protected function processBmp()
|
||||
{
|
||||
throw new NotSupportedException(
|
||||
"BMP format is not supported by Gd Driver."
|
||||
);
|
||||
if ( ! function_exists('imagebmp')) {
|
||||
throw new NotSupportedException(
|
||||
"BMP format is not supported by PHP installation."
|
||||
);
|
||||
}
|
||||
|
||||
ob_start();
|
||||
imagebmp($this->image->getCore());
|
||||
$this->image->mime = defined('IMAGETYPE_BMP') ? image_type_to_mime_type(IMAGETYPE_BMP) : 'image/bmp';
|
||||
$buffer = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -100,16 +100,18 @@ class EncoderTest extends 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);
|
||||
if (function_exists('imagebmp')) {
|
||||
$core = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
|
||||
$encoder = new GdEncoder;
|
||||
$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('image/x-ms-bmp; charset=binary', $this->getMime($encoder->result));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user