Skip to content

Instantly share code, notes, and snippets.

@serid
Created April 22, 2019 21:25
Show Gist options
  • Save serid/47722c5d78fbefe5aa6af5ef32e0af30 to your computer and use it in GitHub Desktop.
Save serid/47722c5d78fbefe5aa6af5ef32e0af30 to your computer and use it in GitHub Desktop.
### This program shuffles pixels in input.jpg and spits them out to output.jpg
###
### Pretty easy huh?
from PIL import Image
from random import shuffle
def main():
im = Image.open("input.jpg")
x, y = im.size
px = im.load()
pxarr = []
for i in range(y):
for j in range(x):
pxarr.append(px[j,i])
shuffle(pxarr)
for i in range(y):
for j in range(x):
px[j,i] = pxarr[i * x + j]
#im.show()
im.save("output.jpg")
pass
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment