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.

Gagan

Hi, there I'm founder of ComputerScienceHub(Started this to bring useful Computer Science information just at one place). Personally I've been doing JavaScript, Python development since 2015(Been long) - Worked upon couple of Web Development Projects, Did some Data Science stuff using Python. Nowadays primarily I work as Freelance JavaScript Developer(Web Developer) and on side-by-side managing team of Computer Science specialists at ComputerScienceHub.io

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts