Pixelize an Image with PIL and Python

As I am trying to make a game with some pixel style in it, just to be in the 80ies game mood, here some simple code is to create a pixelate effect on an image. Let’s say we got this:

Let’s pixelite it

Code to pixelize an image with PIL (pillow)

To install PIL use the fork pillow:

pip install pillow

#!/usr/local/bin/python3
from PIL import Image
import os

# Open The Image to PIXELIZE
img = Image.open("image2.jpg")

# The smallest is the resize, the biggest are the PIXELS
# imgSmall = img.resize((128, 128), resample=Image.BILINEAR)
# If you do want ANTIALISING uncomment the line above and comment the one below
imgSmall = img.resize((256, 256))

# Scale back up using NEAREST to original size
result = imgSmall.resize(img.size,Image.NEAREST)

# Save
result.save('result.png')
os.startfile('result.png')
# os.startfile('image.png')

Images manipulation with Python

Videos


Articoli in evidenza


Giovanni G. Py

I like to solve problems with Python