Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

image_​type_​to_​extension

Description

The image_​type_​to_​extension of Image for PHP get file extension for image type.

Syntax

image_type_to_extension(
    int $image_type,
    bool $include_dot = true
): string|false

Parameters

image_type

One of the IMAGETYPE_XXX constant.

include_dot

Whether to prepend a dot to the extension or not. Default is true.

Return

A string with the extension corresponding to the given image type, or false on failure.

ValueImage TypeExtension
1IMAGETYPE_GIF.gif
2IMAGETYPE_JPEG.jpeg
3IMAGETYPE_PNG.png
4IMAGETYPE_SWF.swf
5IMAGETYPE_PSD.psd
6IMAGETYPE_BMP.bmp
7IMAGETYPE_TIFF_II (intel byte order).tiff
8IMAGETYPE_TIFF_MM (motorola byte order).tiff
9IMAGETYPE_JPC.jpc
10IMAGETYPE_JP2.jp2
11IMAGETYPE_JPX.jpx
12IMAGETYPE_JB2.jb2
13IMAGETYPE_SWC.swf
14IMAGETYPE_IFF.iff
15IMAGETYPE_WBMP.bmp
16IMAGETYPE_XBM.xbm
17IMAGETYPE_ICO.ico
18IMAGETYPE_WEBP.webp
19IMAGETYPE_AVIF.avif

Examples

1 · image_type

<?

$image_type = IMAGETYPE_PNG;

$return = image_type_to_extension($image_type);

echo $return;

?>
.png

2 · include_dot

<?

$image_type = IMAGETYPE_PNG;
$include_dot = false;

$return = image_type_to_extension($image_type, $include_dot);

echo $return;

?>
png

3 · extensions

<?

for($i = 1; $i <= 19; ++$i)
{
    $return = image_type_to_extension($i);

    echo "$i: $return\n";
}

?>
1: .gif
2: .jpeg
3: .png
4: .swf
5: .psd
6: .bmp
7: .tiff
8: .tiff
9: .jpc
10: .jp2
11: .jpx
12: .jb2
13: .swf
14: .iff
15: .bmp
16: .xbm
17: .ico
18: .webp
19: .avif
HomeMenu