Identify image type in Python Python 25.12.2015

There is a standard module for this called imghdr. It's usage is very simple:

from imghdr import what
what('~/images/girls.png')
'png'