summaryrefslogtreecommitdiffstats
path: root/shred.py
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2011-11-13 19:47:28 -0500
committerJason A. Donenfeld <Jason@zx2c4.com>2011-11-13 19:47:28 -0500
commit7ab4a4d6f5575f114d16dc06cfa152b3b3a51db0 (patch)
treed67965427270fb71962b6f57a3a90f90e32cbcc1 /shred.py
downloadinstagram-unshredder-7ab4a4d6f5575f114d16dc06cfa152b3b3a51db0.tar.xz
instagram-unshredder-7ab4a4d6f5575f114d16dc06cfa152b3b3a51db0.zip
Initial commit.
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])