Skip to content

Instantly share code, notes, and snippets.

@sneeu
Created September 6, 2011 08:59
Show Gist options
  • Save sneeu/1197026 to your computer and use it in GitHub Desktop.
Save sneeu/1197026 to your computer and use it in GitHub Desktop.
Upscale an image to double with & height, and put a dithering pattern over it.
from PIL import Image
def dither(im):
width, height = im.size
avg_color = tuple([n / 2 for n in sorted(im.getcolors(width * height))[-1][1]])
new_im = Image.new("RGBA", (width * 2, height * 2), avg_color)
for x in xrange(0, width):
for y in xrange(0, height):
new_im.putpixel((x * 2, y * 2), im.getpixel((x, y)))
return new_im
if __name__ == '__main__':
im = Image.open('unknown.jpg')
new_im = main(im)
new_im.save('unknown2.jpg', 'JPEG')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment