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.
Value | Image Type | Extension |
---|---|---|
1 | IMAGETYPE_GIF | .gif |
2 | IMAGETYPE_JPEG | .jpeg |
3 | IMAGETYPE_PNG | .png |
4 | IMAGETYPE_SWF | .swf |
5 | IMAGETYPE_PSD | .psd |
6 | IMAGETYPE_BMP | .bmp |
7 | IMAGETYPE_TIFF_II (intel byte order) | .tiff |
8 | IMAGETYPE_TIFF_MM (motorola byte order) | .tiff |
9 | IMAGETYPE_JPC | .jpc |
10 | IMAGETYPE_JP2 | .jp2 |
11 | IMAGETYPE_JPX | .jpx |
12 | IMAGETYPE_JB2 | .jb2 |
13 | IMAGETYPE_SWC | .swf |
14 | IMAGETYPE_IFF | .iff |
15 | IMAGETYPE_WBMP | .bmp |
16 | IMAGETYPE_XBM | .xbm |
17 | IMAGETYPE_ICO | .ico |
18 | IMAGETYPE_WEBP | .webp |
19 | IMAGETYPE_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
Links
Image
- gd_info
- getimagesize
- getimagesizefromstring
- image_type_to_extension
- image_type_to_mime_type
- imageaffine
- imageaffinematrixconcat
- imageaffinematrixget
- imagealphablending
- imageantialias
- imagearc
- imageavif
- imagebmp
- imagechar
- imagecharup
- imagecolorallocate
- imagecolorallocatealpha
- imagecolorat
- imagecolorclosest
- imagecolorclosestalpha
- imagecolorclosesthwb
- imagecolordeallocate
- imagecolorexact
- imagecolorexactalpha
- imagecolormatch
- imagecolorresolve
- imagecolorresolvealpha
- imagecolorset
- imagecolorsforindex
- imagecolorstotal
- imagecolortransparent
- imageconvolution
- imagecopy
- imagecopymerge
- imagecopymergegray
- imagecopyresampled
- imagecopyresized
- imagecreate
- imagecreatefromavif
- imagecreatefrombmp
- imagecreatefromgif
- imagecreatefromjpeg
- imagecreatefrompng
- imagecreatefromstring
- imagecreatefromtga
- imagecreatefromwbmp
- imagecreatefromwebp
- imagecreatefromxbm
- imagecreatefromxpm
- imagecreatetruecolor
- imagecrop
- imagecropauto
- imagedashedline
- imagedestroy
- imageellipse
- imagefill
- imagefilledarc
- imagefilledellipse
- imagefilledpolygon
- imagefilledrectangle
- imagefilltoborder
- imagefilter
- imageflip
- imagefontheight
- imagefontwidth
- imageftbbox
- imagefttext
- imagegammacorrect
- imagegetclip
- imagegetinterpolation
- imagegif
- imageinterlace
- imageistruecolor
- imagejpeg
- imagelayereffect
- imageline
- imageloadfont
- imageopenpolygon
- imagepalettecopy
- imagepalettetotruecolor
- imagepng
- imagepolygon
- imagerectangle
- imageresolution
- imagerotate
- imagesavealpha
- imagescale
- imagesetbrush
- imagesetclip
- imagesetinterpolation
- imagesetpixel
- imagesetstyle
- imagesetthickness
- imagesettile
- imagestring
- imagestringup
- imagesx
- imagesy
- imagetruecolortopalette
- imagettfbbox
- imagettftext
- imagetypes
- imagewbmp
- imagewebp
- imagexbm
- iptcembed
- iptcparse