image_type_to_extension()
image_type_to_extension() — Get file extension for image type.
Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.2.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Returns the extension for the given IMAGETYPE_* constant.
Signature
image_type_to_extension(int $image_type, bool $include_dot = true): string|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $image_type | int | One of the IMAGETYPE_* constant. |
| $include_dot | bool | Whether to prepend a dot to the extension or not. Default to true. |
Return value
A string with the extension corresponding to the given image type, or false on failure.
Example
A runnable snippet:
// Create image instance $im = imagecreatetruecolor(100, 100); // Save image imagepng($im, './test' . image_type_to_extension(IMAGETYPE_PNG));
All PHP 8.5 built-in functions
Reference card built from the PHP manual page image_type_to_extension() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.