Skip to content

Commit ab9f6b3

Browse files
committed
adding try catch to avoid script interrumption
1 parent 122339d commit ab9f6b3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

imgwebpconverter.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ def convert_to_webp(path, quality):
2222
print(f'Skipping {image_path}, WebP version already exists.')
2323
continue # Skip to the next file
2424

25-
# Save the image in WebP format with the specified quality
26-
img.save(webp_path, 'webp', quality=quality)
27-
os.remove(image_path)
25+
try:
26+
# Save the image in WebP format with the specified quality
27+
img.save(webp_path, 'webp', quality=quality)
28+
os.remove(image_path)
29+
except Exception as e:
30+
print(f'Error converting {image_path} to WebP: {e}')
31+
continue
32+
2833
print(f'Converted: {image_path} -> {webp_path}')
2934

3035
if __name__ == "__main__":

0 commit comments

Comments
 (0)