Skip to content

Commit

Permalink
added Image::getSupportedTypes()
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 2, 2023
1 parent 494d200 commit c99f377
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Utils/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,21 @@ public static function isTypeSupported(int $type): bool
}


/** @return ImageType[] */
public static function getSupportedTypes(): array
{
$flag = imagetypes();
return array_filter([
$flag & IMG_GIF ? ImageType::GIF : null,
$flag & IMG_JPG ? ImageType::JPEG : null,
$flag & IMG_PNG ? ImageType::PNG : null,
$flag & IMG_WEBP ? ImageType::WEBP : null,
$flag & 256 ? ImageType::AVIF : null, // IMG_AVIF
$flag & IMG_BMP ? ImageType::BMP : null,
]);
}


/**
* Wraps GD image.
*/
Expand Down
2 changes: 2 additions & 0 deletions tests/Utils/Image.isTypeSupported.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ Assert::true(Image::isTypeSupported(Image::GIF));
Assert::true(Image::isTypeSupported(Image::JPEG));
Assert::same(function_exists('imagecreatefromwebp'), Image::isTypeSupported(Image::WEBP));
Assert::same(function_exists('imagecreatefromavif'), Image::isTypeSupported(Image::AVIF));

Assert::contains(Image::GIF, Image::getSupportedTypes());

0 comments on commit c99f377

Please sign in to comment.