1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-03 10:53:01 +02:00

Merge pull request #984 from koenvu/master

Add support for bmp
This commit is contained in:
Oliver Vogel
2021-07-05 18:38:07 +02:00
committed by GitHub
3 changed files with 40 additions and 12 deletions

View File

@@ -55,9 +55,25 @@ class Decoder extends \Intervention\Image\AbstractDecoder
$core = @imagecreatefromwebp($path); $core = @imagecreatefromwebp($path);
break; 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: default:
throw new NotReadableException( 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))
); );
} }

View File

@@ -96,11 +96,21 @@ class Encoder extends \Intervention\Image\AbstractEncoder
*/ */
protected function processBmp() protected function processBmp()
{ {
if ( ! function_exists('imagebmp')) {
throw new NotSupportedException( throw new NotSupportedException(
"BMP format is not supported by Gd Driver." "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;
}
/** /**
* Processes and returns encoded image as ICO string * Processes and returns encoded image as ICO string
* *

View File

@@ -100,16 +100,18 @@ class EncoderTest extends TestCase
$this->assertInstanceOf('Intervention\Image\Image', $img); $this->assertInstanceOf('Intervention\Image\Image', $img);
} }
/**
* @expectedException \Intervention\Image\Exception\NotSupportedException
*/
public function testProcessBmpGd() public function testProcessBmpGd()
{ {
if (function_exists('imagebmp')) {
$core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
$encoder = new GdEncoder; $encoder = new GdEncoder;
$image = Mockery::mock('\Intervention\Image\Image'); $image = Mockery::mock('\Intervention\Image\Image');
$image->shouldReceive('getCore')->once()->andReturn($core);
$image->shouldReceive('setEncoded')->once()->andReturn($image);
$img = $encoder->process($image, 'bmp', 90); $img = $encoder->process($image, 'bmp', 90);
$this->assertInstanceOf('Intervention\Image\Image', $img); $this->assertInstanceOf('Intervention\Image\Image', $img);
$this->assertEquals('image/x-ms-bmp; charset=binary', $this->getMime($encoder->result));
}
} }
/** /**