def image_get_format(f):
f.seek(<NUM_LIT:0>)<EOL>try:<EOL><INDENT>img = Image.open(f)<EOL>t = img.format.lower()<EOL><DEDENT>except IOError:<EOL><INDENT>t = None<EOL><DEDENT>return t<EOL>
Return image format for file-object f. (jpeg, png, gif etc.)
All formats: http://pillow.readthedocs.org/en/latest/handbook/image-file-formats.html
Example:
    if image_get_format(request.FILES['image']) == 'jpeg':
        print 'Image is JPEG'

    if image_get_format(open('/tmp/image.png', 'rb')) == 'png':
        print 'File is PNG'