code: def image_get_format(f):
      
      f.seek(0)
      try:
          img = Image.open(f)
          t = img.format.lower()
      except IOError:
          t = None
      return t
docs: 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'