PHP image_type_to_extension() Function Last Updated : 26 May, 2023 Comments Improve Suggest changes Like Article Like Report The image_type_to_extension() function is an inbuilt function in PHP which is used to get the file extension for an image type. This function can be found in any PHP version similar or greater than 5.2.0. Syntax: string image_type_to_extension( int $imagetype, bool $include_dot ) Parameters: This function accepts two parameters as mentioned above and described below: $imagetype: It takes an integer value as first parameter that is one of the IMAGETYPE_XXX constant. For example: IMAGETYPE_GIF, IMAGETYPE_JPEG etc.$include_dot: The second parameter takes a boolean value to decide whether to prepend a dot to the extension or not. The default value is set to TRUE in the function. Return Value: This function returns a string value associated with the extension corresponding to the given image type. Below programs illustrate the image_type_to_extension() function in PHP. Program 1: php <?php // Extension with dot echo image_type_to_extension(IMAGETYPE_PNG, TRUE) . "\n"; // Extension without dot echo image_type_to_extension(IMAGETYPE_PNG, FALSE); ?> Output: .png png Program 2: php <?php // Create image instance $image = imagecreatetruecolor(100, 100); // Creates an image with .png extension imagepng($image, './test' . image_type_to_extension(IMAGETYPE_PNG)); // Free any memory associated with image imagedestroy($image); ?> Output: Creates an image with name test.png Reference: https://www.php.net/manual/en/function.image-type-to-extension.php Create Quiz Comment S ShrabanaBiswas Follow 0 Improve S ShrabanaBiswas Follow 0 Improve Article Tags : Web Technologies PHP Image-Processing PHP-function Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like