Open In App

PHP | exif_imagetype() function

The exif_imagetype() function is an inbuilt function in PHP which is used to determine the type of an image.
Syntax: 
 

int exif_imagetype( string $filename )

Parameters:This function accepts a single parameter $filename which holds the name or URL of the image.
Return Value: This function returns an integer corresponding to one of IMAGETYPE constants as given below: 
 



Below given programs illustrate the exif_imagetype() function in PHP: 
Program 1: In this example we will check the format of a image file. 
 




<?php
// Load an image from PNG URL
$type = exif_imagetype(
 
echo $type;
?>

Output: 
 



3 // which corresponds to IMAGETYPE_PNG

Program 2: In this example we will check if a image file is supported or not. 
 




<?php
// Load an image from JPEG URL
$type = exif_imagetype(
 
if($type > 0 || $type < 19)
{
    echo 'This is a supported image format.';
}
?>

Output: 
 

This is a supported image format.

Reference: https://www.php.net/manual/en/function.exif-imagetype.php
 

Article Tags :