Skip to content

Instantly share code, notes, and snippets.

@lmzach09
Created September 8, 2019 21:30
Show Gist options
  • Save lmzach09/ff2aa6b106773b84c80db37d7720f2e4 to your computer and use it in GitHub Desktop.
Save lmzach09/ff2aa6b106773b84c80db37d7720f2e4 to your computer and use it in GitHub Desktop.
pyqt app example snippet for detecting valid image files from file names
DEFAULT_IMAGE_ALBUM_DIRECTORY = './my-album/'
## Check that a file name has a valid image extension for QPixmap
def filename_has_image_extension(filename):
valid_img_extensions = \
['bmp', 'gif', 'jpg', 'jpeg', 'png', 'pbm', 'pgm', 'ppm', 'xbm', 'xpm']
filename = filename.lower()
extension = filename[-3:]
four_char = filename[-4:] ## exclusively for jpeg
if extension in valid_img_extensions or four_char in valid_img_extensions:
return True
else:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment