Skip to content

Instantly share code, notes, and snippets.

@davethegr8
Forked from danyshaanan/pixelate_image.py
Created November 7, 2013 16:25
Show Gist options
  • Save davethegr8/7357411 to your computer and use it in GitHub Desktop.
Save davethegr8/7357411 to your computer and use it in GitHub Desktop.
from PIL import Image
backgroundColor = (0,)*3
pixelSize = 9
image = Image.open('input.png')
image = image.resize((image.size[0]/pixelSize, image.size[1]/pixelSize), Image.NEAREST)
image = image.resize((image.size[0]*pixelSize, image.size[1]*pixelSize), Image.NEAREST)
pixel = image.load()
for i in range(0,image.size[0],pixelSize):
for j in range(0,image.size[1],pixelSize):
for r in range(pixelSize):
pixel[i+r,j] = backgroundColor
pixel[i,j+r] = backgroundColor
image.save('output.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment