Skip to content

Instantly share code, notes, and snippets.

@Refffy
Created January 21, 2021 14:54
Show Gist options
  • Save Refffy/c90a38b70348be183d6974dba20814c8 to your computer and use it in GitHub Desktop.
Save Refffy/c90a38b70348be183d6974dba20814c8 to your computer and use it in GitHub Desktop.
from PIL import Image
from sys import argv
def pixelate(inpt, outpt, colors, k):
img = Image.open(inpt).convert('P', palette=Image.ADAPTIVE, colors=colors)
w, h = img.size
img = img.resize((285, 385)).resize((w, h), Image.NEAREST)
img.quantize(colors=colors, kmeans=k)
img.save(outpt)
if __name__ == '__main__':
pixelate(argv[1], argv[2], int(argv[3]), int(argv[4]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment