from PIL import Image
pixel_size = 8
image = Image.open("in.png")
orginal_size = image.size
image = image.resize((orginal_size[0] // pixel_size, orginal_size[1] // pixel_size), Image.NEAREST)
image = image.resize(orginal_size, Image.NEAREST)
image.save("pixelated.png")

🚧 What It Does

This simple program pixelates an image to any pixel size.

📙 What I learned

I learned how to use PIL and it's methods.

🛠️ How I Built It

It took me some time to actually figure out an easy way to create pixelated images. The logic is simple. Once the PIL image object is initialized, the image is resized to the size divided by the pixel_size (PIL doesn't accept decimal resize dimensions, so // removes any remainder). The image is now smaller, so when it gets enlarged to it's original dimensions, it's blurry, or pixelated 🤯.

This logic/technique can be implemented in any programming language with any image library, as long as the library has resizing capabilities.

Built With

Share this project:

Updates