import photos, console from ImageEnhance import Contrast, Brightness from ImageOps import autocontrast from PIL import Image def enhance(im, enhancement, value): """Friendly wrapper for ImageEnhance""" e = enhancement(im) return e.enhance(value) def palette(white): """Build a linear palette""" colors = [] r, g, b = white for i in range(255): colors.extend((r*i/255, g*i/255, b*i/255)) return colors def color_tint(im, rgb): """Apply a tinted palette""" im = im.convert("L") im.putpalette(palette(rgb)) return im.convert("RGB") def boost_levels(im, contrast = 2, brightness = 0.7): """Tweak levels for the stark Gotham look""" return enhance(enhance(im, Brightness, brightness), Contrast, contrast) def red_bw(im, rgb = (1, -0.4, -0.6)): """Simulate a red B&W filter - let red through, darken other components""" r, g, b, _ = im.split() _, g_luma, b_luma = rgb # ignore red g = enhance(g, Brightness, g_luma) b = enhance(b, Brightness, b_luma) im = Image.merge("RGB",(r,g,b)) return im.convert('L') # Let the user pick a photo original = photos.pick_image(show_albums=True) # Turn on the progress indicator console.show_activity() # Work with a manageable size no bigger than 1024px either way - comment this out for full res original.thumbnail((1024,1024),Image.ANTIALIAS) gotham = color_tint(boost_levels(autocontrast(red_bw(original))),(248, 255, 250)) # Save the result to the camera roll photos.save_image(gotham) gotham.show() # Turn off the progress indicator console.hide_activity()