Permalink
Browse files
Image: added support for BMP
- Loading branch information
Showing
with
22 additions
and
2 deletions.
-
+7
−2
src/Utils/Image.php
-
+15
−0
tests/Utils/Image.save.phpt
|
@@ -115,11 +115,12 @@ class Image |
|
|
JPEG = IMAGETYPE_JPEG, |
|
|
PNG = IMAGETYPE_PNG, |
|
|
GIF = IMAGETYPE_GIF, |
|
|
WEBP = 18; // IMAGETYPE_WEBP is available as of PHP 7.1 |
|
|
WEBP = IMAGETYPE_WEBP, |
|
|
BMP = IMAGETYPE_BMP; |
|
|
|
|
|
public const EMPTY_GIF = "GIF89a\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00!\xf9\x04\x01\x00\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;"; |
|
|
|
|
|
private const FORMATS = [self::JPEG => 'jpeg', self::PNG => 'png', self::GIF => 'gif', self::WEBP => 'webp']; |
|
|
private const FORMATS = [self::JPEG => 'jpeg', self::PNG => 'png', self::GIF => 'gif', self::WEBP => 'webp', self::BMP => 'bmp']; |
|
|
|
|
|
/** @var resource */ |
|
|
private $image; |
|
@@ -569,6 +570,10 @@ private function output(int $type, ?int $quality, string $file = null): void |
|
|
$success = @imagewebp($this->image, $file, $quality); // @ is escalated to exception |
|
|
break; |
|
|
|
|
|
case self::BMP: |
|
|
$success = @imagebmp($this->image, $file); // @ is escalated to exception |
|
|
break; |
|
|
|
|
|
default: |
|
|
throw new Nette\InvalidArgumentException("Unsupported image type '$type'."); |
|
|
} |
|
|
|
@@ -46,6 +46,21 @@ test(function () use ($main) { |
|
|
}); |
|
|
|
|
|
|
|
|
test(function () use ($main) { |
|
|
if (!function_exists('imagebmp')) { |
|
|
return; |
|
|
} |
|
|
|
|
|
$main->save(getTempDir() . '/foo.bmp'); |
|
|
Assert::true(is_file(getTempDir() . '/foo.bmp')); |
|
|
Assert::same(IMAGETYPE_BMP, getimagesize(getTempDir() . '/foo.bmp')[2]); |
|
|
|
|
|
$main->save(getTempDir() . '/foo.y', null, Image::BMP); |
|
|
Assert::true(is_file(getTempDir() . '/foo.y')); |
|
|
Assert::same(IMAGETYPE_BMP, getimagesize(getTempDir() . '/foo.y')[2]); |
|
|
}); |
|
|
|
|
|
|
|
|
Assert::exception(function () use ($main) { // invalid image type |
|
|
$main->save('foo', null, IMG_WBMP); |
|
|
}, Nette\InvalidArgumentException::class, sprintf('Unsupported image type \'%d\'.', IMG_WBMP)); |
|
|
0 comments on commit
711b1ac