Skip to content

Commit

Permalink
use context manager for opening image
Browse files Browse the repository at this point in the history
  • Loading branch information
rchan26 committed Sep 19, 2024
1 parent 103a6b0 commit b6257fe
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/prompto/scripts/convert_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def main():
for item in tqdm(os.listdir(args.folder)):
file = os.path.join(args.folder, item)
if file.lower().endswith(".jpg") or file.lower().endswith(".jpeg"):
image = Image.open(file)
converted_image = image.convert("RGB")
converted_image.save(file, "JPEG")
with Image.open(file) as image:
converted_image = image.convert("RGB")
converted_image.save(file, "JPEG")
elif file.lower().endswith(".png"):
image = Image.open(file)
converted_image = image.convert("RGB")
converted_image.save(file, "PNG")
with Image.open(file) as image:
converted_image = image.convert("RGB")
converted_image.save(file, "PNG")
else:
logging.info(f"Skipping {file} as it is not a supported file type")

Expand Down

0 comments on commit b6257fe

Please sign in to comment.