File tree 1 file changed +9
-8
lines changed
IMAGES & PHOTO SCRIPTS/Image-Inverter
1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env python3
2
2
3
- from PIL import Image
4
- from PIL import ImageOps
3
+ from PIL import Image , ImageOps , UnidentifiedImageError
5
4
import sys , os
6
5
7
6
def check_input ():
@@ -27,12 +26,14 @@ def main():
27
26
28
27
image_path_no_ext , extension = os .path .splitext (file )
29
28
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." )
36
37
i = i + 1
37
38
38
39
if __name__ == '__main__' :
You can’t perform that action at this time.
0 commit comments