Python has many modules in its standard library. One that is often overlooked is imghdr which lets you identify what image type that is contained in a file, byte stream or path-like object.
The imghdr can recognize the following image types:
Keep reading with a 7-day free trial
Subscribe to The Python Papers to keep reading this post and get 7 days of free access to the full post archives.