From 7ab4a4d6f5575f114d16dc06cfa152b3b3a51db0 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 13 Nov 2011 19:47:28 -0500 Subject: Initial commit. --- shred.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 shred.py (limited to 'shred.py') 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 +# 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]) -- cgit v1.2.3-59-g8ed1b