Created
July 16, 2013 11:30
-
-
Save ruiwen/6007928 to your computer and use it in GitHub Desktop.
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
| import re | |
| import PIL | |
| from PIL import Image | |
| def generate_thumbnails(fn): | |
| match = re.match(r"^(?P<path>[^/]+)/receipt_(?P<dimensions>\d{4}x\d{4})_(?P<mp>.{3,5})\.jpg$", fn) | |
| if not match: | |
| return | |
| print "Generating for " + fn | |
| match = match.groupdict() | |
| im = Image.open(fn) | |
| ds = [0.2, 0.3, 0.4, 0.5, 0.6, 0.7] | |
| qs = [20, 30, 40, 50] | |
| cs = [{"d": d, "q": q} for d in ds for q in qs] | |
| for c in cs: | |
| c.update({"path": match['path'], "mp": match['mp']}) | |
| im.resize(map(lambda x: int(x*c['d']), im.size), PIL.Image.ANTIALIAS).save("%(path)s/receipt_%(mp)s_%(d)sD_%(q)sQ.jpg" % c, "JPEG", quality=c['q']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment