-
-
Save himanshuxd/39b8d28bc20cfcee1c6dff0966b42e27 to your computer and use it in GitHub Desktop.
A Python script to pixelate an image and add a thin black margin between the simulated pixels.
This file contains 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
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