def valid_img(f):
"""
Is this a valid image that we can use to upload?
:param f: str that indicates the file directory.
:return: boolean
"""
if not os.path.isfile(f) :
return False
if re.search(r'\.(jpg|gif|png|tiff|mp4|mp2|avi|wmv|mov|m4v)$', f, flags=re.IGNORECASE):
return True
try:
file_type = imghdr.what(f)
supported_types = ['jpeg', 'gif', 'png']
if file_type in supported_types:
return True
except AttributeError as e:
# You probably passed something that is not a path.
logging.warning(e)
except IOError as e:
# You passed a path that does not exist, or you do not have access to it.
logging.warning(e)
return False
评论列表
文章目录