Created
September 8, 2019 21:30
-
-
Save lmzach09/ff2aa6b106773b84c80db37d7720f2e4 to your computer and use it in GitHub Desktop.
pyqt app example snippet for detecting valid image files from file names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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