summaryrefslogtreecommitdiffstats
path: root/shred.py
diff options
context:
space:
mode:
Diffstat (limited to 'shred.py')
-rwxr-xr-xshred.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/shred.py b/shred.py
new file mode 100755
index 0000000..40face9
--- /dev/null
+++ b/shred.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+# Instagram Shredder
+# by Jason A. Donenfeld <Jason@zx2c4.com>
+# for http://instagram-engineering.tumblr.com/post/12651721845/instagram-engineering-challenge-the-unshredder
+
+from PIL import Image
+from random import shuffle
+from sys import argv, exit, stderr
+
+if len(argv) < 4:
+ print >> stderr, "Usage: %s columns input output" % argv[0]
+ exit(-1)
+
+columns = int(argv[1])
+image = Image.open(argv[2])
+shredded = Image.new("RGBA", image.size)
+width, height = image.size
+shred_width = width / columns
+sequence = range(0, columns)
+shuffle(sequence)
+
+for i, shred_index in enumerate(sequence):
+ shred_x1, shred_y1 = shred_width * shred_index, 0
+ shred_x2, shred_y2 = shred_x1 + shred_width, height
+ region = image.crop((shred_x1, shred_y1, shred_x2, shred_y2))
+ shredded.paste(region, (shred_width * i, 0))
+
+shredded.save(argv[3])