Skip to content

Instantly share code, notes, and snippets.

@megadix
Created May 17, 2024 06:33
Show Gist options
  • Save megadix/7c901c737a16ee936c22d3b387876d3d to your computer and use it in GitHub Desktop.
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
# 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