This question already has an answer here:
- Automatic image format detection in PHP 7 answers
Are there libraries in PHP or JS which can identify image formats by analyzing data? It should support BMP, JPG, GIF, PNG, TIFF and EMF.
</div>
This question already has an answer here:
Are there libraries in PHP or JS which can identify image formats by analyzing data? It should support BMP, JPG, GIF, PNG, TIFF and EMF.
</div>
Try this function with PHP getimagesize
:-
function is_image($path)
{
$a = getimagesize($path);
$image_type = $a[2];
//Add you image format
if(in_array($image_type , array(IMAGETYPE_GIF , IMAGETYPE_JPEG ,IMAGETYPE_PNG , IMAGETYPE_BMP)))
{
return true;
}
return false;
}
or you can use exif_imagetype
//Add you image format
if (exif_imagetype('image.gif') != IMAGETYPE_GIF) {
echo 'The picture is not a gif';
}