Created
October 24, 2017 17:34
-
-
Save say4n/535713dc6b3b7b9abbd2c0281dcf0140 to your computer and use it in GitHub Desktop.
Pixelate an image without changing it's resolution!
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
#!/usr/bin/env python3 | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import PIL | |
import PIL.Image as Image | |
plt.axis('off') | |
dname, iname, fmt = "/Users/Photos/", "avatar", "jpg" | |
img = Image.open(dname + iname + "." + fmt) | |
scl = 8 | |
shape = np.array(img).shape | |
output = img.resize((shape[0]//scl, shape[1]//scl), resample=PIL.Image.LANCZOS) | |
output = output.resize(shape[:2], resample=PIL.Image.BOX) | |
plt.imshow(output) | |
plt.show() | |
output.save(dname + iname + "-pixelated.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment