Refactor resize-img error printing
This commit is contained in:
parent
3c1f996342
commit
22a70bd4de
@ -5,12 +5,11 @@ import sys
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
argn = len(sys.argv)
|
argn = len(sys.argv)
|
||||||
|
|
||||||
if argn == 1:
|
if argn == 1:
|
||||||
print("Error: You must specify an input file")
|
print_error("You must specify an input file")
|
||||||
exit(1)
|
exit(1)
|
||||||
elif argn == 2:
|
elif argn == 2:
|
||||||
print("Error: You must specify an output file")
|
print_error("You must specify an output file")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
input_image_path = sys.argv[1]
|
input_image_path = sys.argv[1]
|
||||||
@ -19,7 +18,7 @@ def main():
|
|||||||
try:
|
try:
|
||||||
image = Image.open(input_image_path)
|
image = Image.open(input_image_path)
|
||||||
except IOError:
|
except IOError:
|
||||||
print(f"Error: Cannot open image file {input_image_path}")
|
print_error(f"Cannot open image file {input_image_path}")
|
||||||
image.close()
|
image.close()
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
@ -37,11 +36,15 @@ def main():
|
|||||||
try:
|
try:
|
||||||
image.save(output_image_path, **kwargs)
|
image.save(output_image_path, **kwargs)
|
||||||
except IOError:
|
except IOError:
|
||||||
print(f"Error: Cannot save file {output_image_path}")
|
print_error(f"Cannot save file {output_image_path}")
|
||||||
image.close()
|
image.close()
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def print_error(string):
|
||||||
|
print(f"resize-img Error: {string}")
|
||||||
|
|
||||||
|
|
||||||
def rotate_image(image):
|
def rotate_image(image):
|
||||||
exif = image.getexif()
|
exif = image.getexif()
|
||||||
if exif is None:
|
if exif is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user