File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed
IMAGES & PHOTO SCRIPTS/Image-Inverter Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change 11#!/usr/bin/env python3
22
3- from PIL import Image
4- from PIL import ImageOps
3+ from PIL import Image , ImageOps , UnidentifiedImageError
54import sys , os
65
76def check_input ():
@@ -27,12 +26,14 @@ def main():
2726
2827 image_path_no_ext , extension = os .path .splitext (file )
2928
30- with Image .open (file ) as image :
31- new_path_with_ext = image_path_no_ext + "_inverted" + extension
32- ImageOps .invert (image ).save (new_path_with_ext )
33- if verbose_enabled :
34- print ("Successfully inverted " + file + "\n " + new_path_with_ext + " is generated.\n " )
35-
29+ try :
30+ with Image .open (file ) as image :
31+ new_path_with_ext = image_path_no_ext + "_inverted" + extension
32+ ImageOps .invert (image ).save (new_path_with_ext )
33+ if verbose_enabled :
34+ print ("Successfully inverted " + file + "\n " + new_path_with_ext + " is generated.\n " )
35+ except UnidentifiedImageError :
36+ print (file + " is not suppotred, please provide a supported file type." )
3637 i = i + 1
3738
3839if __name__ == '__main__' :
You can’t perform that action at this time.
0 commit comments