<?php
int|false exif_imagetype ( string $filename )
where,
$filename = The image file to be checked
?>
<?php
string image_type_to_mime_type ( int $image_type )
where,
$image_type = One the IMAGETYPE_XXX constants
(SEE the below TABLE)
?>
<?php
array get_defined_constants( bool $categorize = false )
where,
$categorize =
?>
<?php
// PHP version dependent display
echo 'PHP ' . PHP_VERSION . '<br><br>';
$arr = get_defined_constants(true);
/*
echo '<pre>';
print_r($arr['standard']);
echo '</pre>';
*/
foreach($arr['standard'] as $k => $v)
{
if(strchr($k, 'IMAGETYPE_'))
echo "$k => $v => " . image_type_to_mime_type($v) . '<br>';
}
?>
IMAGETYPE_XXX_ PHP 8.2.22 | ||
VALUE | CONSTANT | TYPE |
1 | IMAGETYPE_GIF | image/gif |
2 | IMAGETYPE_JPEG | image/jpeg |
3 | IMAGETYPE_PNG | image/png |
4 | IMAGETYPE_SWF | application/x-shockwave-flash |
5 | IMAGETYPE_PSD | image/psd |
6 | IMAGETYPE_BMP | image/bmp |
7 | IMAGETYPE_TIFF_II | image/tiff |
8 | IMAGETYPE_TIFF_MM | image/tiff |
9 | IMAGETYPE_JPC | application/octet-stream |
10 | IMAGETYPE_JP2 | image/jp2 |
11 | IMAGETYPE_JPX | application/octet-stream |
12 | IMAGETYPE_JB2 | application/octet-stream |
13 | IMAGETYPE_SWC | application/x-shockwave-flash |
14 | IMAGETYPE_IFF | image/iff |
15 | IMAGETYPE_WBMP | image/vnd.wap.wbmp |
9 | IMAGETYPE_JPEG2000 | application/octet-stream |
16 | IMAGETYPE_XBM | image/xbm |
17 | IMAGETYPE_ICO | image/vnd.microsoft.icon |
18 | IMAGETYPE_WEBP | image/webp |
19 | IMAGETYPE_AVIF | image/avif |
0 | IMAGETYPE_UNKNOWN | application/octet-stream |
20 | IMAGETYPE_COUNT | application/octet-stream |
ed48 |
<?php
$arr_img01 = [ 'E 01 01.gif',
'E 01 02.jpg',
'E 01 03.png',
'E 01 06.bmp',
'E 01 17.ico',
'E 01 18.webp' ];
foreach($arr_img01 as $img01)
{
$img_type = exif_imagetype('img/' . $img01);
echo $img01 . '<br><br>exif_imagetype = '.
$img_type . '<br><img src="' . 'img/' .
$img01 . '" alt="' . $img01 .
'" width="90%" title="' . $img01 . '"><br>';
$mime_type = image_type_to_mime_type($img_type);
echo $mime_type . '<br><br><br>';
}
?>
<?php
$arr_img02 = [ 'E 02 01.klm',
'E 02 02.xyz',
'E 02 02.THM',
'E 02 03.stu' ];
foreach($arr_img02 as $img02)
{
$img_type = exif_imagetype('img/' . $img02);
echo $img02 . '<br><br>exif_imagetype = '.
$img_type . '<br><img src="' . 'img/' .
$img02 . '" alt="' . $img02 .
'" width="90%" title="' . $img02 . '"><br>';
$mime_type = image_type_to_mime_type($img_type);
echo $mime_type . '<br><br><br>';
}
echo 'The images used in this exercise have
unofficial type names.<br><br>
This supports the claim that this function
reads the first bytes of an image file and
cheks its signature.';
?>