Skip to content

Instantly share code, notes, and snippets.

@artschwagerb
Created May 17, 2015 00:54
Show Gist options
  • Save artschwagerb/47ae62662ac3ae78aad7 to your computer and use it in GitHub Desktop.
Save artschwagerb/47ae62662ac3ae78aad7 to your computer and use it in GitHub Desktop.
Convert JPEG to BMP
import os
from PIL import Image
size = 145, 145
dir_path = '/Users/brian/Desktop/systems'
for filename in os.listdir(dir_path):
if filename.endswith('.bmp'):
# Destroy Previously Converted BMP
try:
os.remove(os.path.join(dir_path,filename.replace('.jpg','.bmp')))
except:
pass
elif filename.endswith('.jpg'):
# Open Image
im = Image.open(os.path.join(dir_path, filename))
# Quality Control
#im.save(os.path.join(dir_path, filename), quality=-50)
# What if the world had a set number of colors
im = im.convert(mode="P", palette=Image.ADAPTIVE, colors=256)
# To bmp
im = im.convert("RGB")
# Thumbnail
im.thumbnail(size)
# Print Shop Deluxe
im.save(os.path.join(dir_path,filename.replace('.jpg','.bmp')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment