Check Image File Type Using Python

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

  1. Import imghdr module
  2. Pass name of file to imghdr module function what()
  3. 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.

Comments to: Check Image File Type Using Python

Your email address will not be published.