Skip to content

Instantly share code, notes, and snippets.

@artschwagerb
Created May 16, 2015 02:09
Show Gist options
  • Save artschwagerb/671210239aabede5593a to your computer and use it in GitHub Desktop.
Save artschwagerb/671210239aabede5593a to your computer and use it in GitHub Desktop.
PIL - Convert to bmp, and resize
import os
from PIL import Image
size = 145, 145
dir_path = '/Users/brian/Desktop/systems_silly'
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'):
# Quality Control
im = Image.open(os.path.join(dir_path, filename))
#im.save(os.path.join(dir_path, filename), quality=-50)
# What if the world was black and white
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