Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<getimagesizefromstringimage_type_to_mime_type>
^GD and Image FunctionsLast updated: Mon, 26 Oct 2026

image_type_to_extension

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

image_type_to_extension — Get file extension for image type

Description

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

Returns the extension for the given IMAGETYPE_* constant.

Parameters

image_type

One of the IMAGETYPE_* constant.

include_dot

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

Return Values

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

Examples

Example #1 image_type_to_extension() example

<?php
// Create image instance
$im = imagecreatetruecolor(100, 100);

// Save image
imagepng($im, './test' . image_type_to_extension(IMAGETYPE_PNG));
?>

Notes

Note:

This function does not require the GD image library.


<getimagesizefromstringimage_type_to_mime_type>
^GD and Image FunctionsLast updated: Mon, 26 Oct 2026