code: def file_type(self, file):
          
          try:
              magic_text = magic.from_file(file)
              if (isinstance(magic_text, bytes)):
                  # In python2 and travis python3 (?!) decode to get unicode string
                  magic_text = magic_text.decode('utf-8')
          except (TypeError, IOError):
              return
          if (re.search('PNG image data', magic_text)):
              return('png')
          elif (re.search('JPEG image data', magic_text)):
              return('jpg')
          # failed
          return
docs: Use python-magic to determine file type.
  
          Returns 'png' or 'jpg' on success, nothing on failure.