Skip to content

Commit 1f4f187

Browse files
committed
added Image::getSupportedTypes()
1 parent f58515d commit 1f4f187

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Utils/Image.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,21 @@ public static function isTypeSupported(int $type): bool
320320
}
321321

322322

323+
/** @return ImageType[] */
324+
public static function getSupportedTypes(): array
325+
{
326+
$flag = imagetypes();
327+
return array_filter([
328+
$flag & IMG_GIF ? ImageType::GIF : null,
329+
$flag & IMG_JPG ? ImageType::JPEG : null,
330+
$flag & IMG_PNG ? ImageType::PNG : null,
331+
$flag & IMG_WEBP ? ImageType::WEBP : null,
332+
$flag & 256 ? ImageType::AVIF : null, // IMG_AVIF
333+
$flag & IMG_BMP ? ImageType::BMP : null,
334+
]);
335+
}
336+
337+
323338
/**
324339
* Wraps GD image.
325340
*/

tests/Utils/Image.isTypeSupported.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ Assert::true(Image::isTypeSupported(Image::GIF));
1717
Assert::true(Image::isTypeSupported(Image::JPEG));
1818
Assert::same(function_exists('imagecreatefromwebp'), Image::isTypeSupported(Image::WEBP));
1919
Assert::same(function_exists('imagecreatefromavif'), Image::isTypeSupported(Image::AVIF));
20+
21+
Assert::contains(Image::GIF, Image::getSupportedTypes());

0 commit comments

Comments
 (0)