Skip to content

Instantly share code, notes, and snippets.

@deepakkhattar26o2
Created January 11, 2022 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepakkhattar26o2/0272727d07d035e3e741845561d2cc3d to your computer and use it in GitHub Desktop.
Save deepakkhattar26o2/0272727d07d035e3e741845561d2cc3d to your computer and use it in GitHub Desktop.
Converts a given image into pixel art
from PIL import Image
import matplotlib.pyplot as pyp
def pixelate(image, i_size):
img = Image.open(image)
small_img = img.resize(i_size, Image.BILINEAR)
res = small_img.resize(img.size, Image.NEAREST)
filename = f"image_{i_size[0]}x{i_size[1]}.png"
res.save(filename)
pyp.figure(figsize=(10, 10))
pyp.subplot(1, 2, 1)
pyp.title("Original image", size=18)
pyp.imshow(img)
pyp.axis("off")
pyp.subplot(1, 2, 2)
pyp.title(f"Pixel Art {i_size[0]}x{i_size[1]}", size=18)
pyp.imshow(res)
pyp.axis("off")
pyp.show()
pixelate(image="nr.jpg", i_size=(128, 128))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment