Created
May 17, 2024 06:33
-
-
Save megadix/7c901c737a16ee936c22d3b387876d3d to your computer and use it in GitHub Desktop.
Python script to convert JFIF images to JPEG - useful for images generated by Image Creator from Microsoft Bing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Prerequisites: | |
# 1. Python 3.x | |
# 2. Pillow library (PIL fork) | |
# pip install pillow | |
import os | |
import sys | |
from PIL import Image | |
dir_path = None | |
total_freed_space = 0 | |
num_deleted_files = 0 | |
if len(sys.argv) > 1: | |
dir_path = sys.argv[1] | |
if not os.path.isdir(dir_path): | |
raise Exception("Specified argument is not a folder or does not exist: {}".format(dir_path)) | |
else: | |
dir_path = os.getcwd() | |
print("Converting JFIF to JPG in dir: {}".format(dir_path)) | |
files = os.listdir(dir_path) | |
for file in files: | |
# Check if the file is a .jfif file | |
if file.endswith('.jfif'): | |
dest_name = file.rsplit('.', 1)[0] + '.jpg' | |
print("Converting: {} => {}".format(file, dest_name)) | |
img = Image.open(os.path.join(dir_path, file)) | |
# Convert and save as .jpeg | |
img.save(os.path.join(dir_path, dest_name), 'JPEG') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment