2323use SMF \Utils ;
2424use SMF \WebFetch \WebFetchApi ;
2525
26- // IMAGETYPE_AVIF was added in PHP 8.1
27- if (!\defined ('IMAGETYPE_AVIF ' )) {
28- \define ('IMAGETYPE_AVIF ' , 19 );
29- }
30-
3126/**
3227 * Represents an image and allows low-level graphics operations to be performed,
3328 * specially as needed for avatars, attachments, etc.
@@ -43,20 +38,35 @@ class Image
4338
4439 // Maps certain IMAGETYPE_* constants to ImageMagick formats.
4540 public const IMAGETYPE_TO_IMAGICK = [
46- IMAGETYPE_BMP => 'bmp ' ,
4741 IMAGETYPE_GIF => 'gif ' ,
48- IMAGETYPE_ICO => 'ico ' ,
49- IMAGETYPE_JP2 => 'jp2 ' ,
5042 IMAGETYPE_JPEG => 'jpeg ' ,
51- IMAGETYPE_JPEG2000 => 'jp2 ' ,
5243 IMAGETYPE_PNG => 'png ' ,
5344 IMAGETYPE_PSD => 'psd ' ,
45+ IMAGETYPE_BMP => 'bmp ' ,
5446 IMAGETYPE_TIFF_II => 'tiff ' ,
5547 IMAGETYPE_TIFF_MM => 'tiff ' ,
48+ IMAGETYPE_JPC => 'j2c ' ,
49+ IMAGETYPE_JP2 => 'jp2 ' ,
5650 IMAGETYPE_WBMP => 'wbmp ' ,
57- IMAGETYPE_WEBP => 'webp ' ,
5851 IMAGETYPE_XBM => 'xbm ' ,
52+ IMAGETYPE_ICO => 'ico ' ,
53+ IMAGETYPE_WEBP => 'webp ' ,
5954 IMAGETYPE_AVIF => 'avif ' ,
55+ // IMAGETYPE_HEIF, added in PHP 8.5.
56+ 20 => 'heic ' , // No, that 'c' is not a typo.
57+ // IMAGETYPE_SVG, added in PHP 8.5 when libxml is loaded.
58+ 21 => 'svg ' ,
59+ ];
60+
61+ // Maps certain IMAGETYPE_* constants to IMG_* constants.
62+ public const IMAGETYPE_TO_IMG = [
63+ IMAGETYPE_GIF => IMG_GIF ,
64+ IMAGETYPE_JPEG => IMG_JPG ,
65+ IMAGETYPE_PNG => IMG_PNG ,
66+ IMAGETYPE_BMP => IMG_BMP ,
67+ IMAGETYPE_WBMP => IMG_WBMP ,
68+ IMAGETYPE_WEBP => IMG_WEBP ,
69+ IMAGETYPE_AVIF => IMG_AVIF ,
6070 ];
6171
6272 /*******************
@@ -548,7 +558,7 @@ public static function getSupportedFormats(): array
548558 }
549559 } elseif (\extension_loaded ('gd ' )) {
550560 foreach (self ::getImageTypes () as $ name => $ int ) {
551- if (imagetypes () & $ int ) {
561+ if (imagetypes () & ( self :: IMAGETYPE_TO_IMG [ $ int] ?? 0 ) ) {
552562 self ::$ supported [$ name ] = $ int ;
553563 }
554564 }
0 commit comments