You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

26 lines
923 B

#!/usr/bin/env python
import os, sys
import Image
import ImageEnhance
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--width", dest="width", type=int, required=True)
parser.add_argument("--height", dest="height", type=int, required=True)
parser.add_argument("source", type=str)
parser.add_argument("destination", type=str)
args = parser.parse_args()
size = args.width, args.height
infile = args.source
outfile = args.destination
try:
im = Image.open(infile)
im = im.convert()
im.thumbnail(size, Image.ANTIALIAS)
im_result = Image.new('RGB', (args.width, args.height), (255, 255, 255))
im_result.paste(im, ((args.width - im.size[0]) / 2, (args.height - im.size[1]) / 2))
enhancer = ImageEnhance.Contrast(im_result)
im_result = enhancer.enhance(1.05)
im_result.save(outfile, "JPEG", quality=100)
except IOError:
print("cannot create thumbnail for '%s'" % infile)