If any image is given and you want to check its file type, then python module imghdr can be used.
Python Code for Checking Image File Type
- Import imghdr module
- Pass name of file to imghdr module function what()
- what() function will return image file type like gif, pgm, jpeg
# Importing Python Module imghdr import imghdr # Calling what function of imghdr module print(imghdr.what("image_file"))
That’s it just two lines of Python Code, this is one of reason why Python is my favourite programming language. So simple to implement.