-
Notifications
You must be signed in to change notification settings - Fork 23
/
shredder.py
37 lines (31 loc) · 1.16 KB
/
shredder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- coding: utf-8 -*-
from PIL import Image
from random import shuffle
import argparse
class Shredder:
def get_args(self):
parser = argparse.ArgumentParser()
parser.add_argument('--path', help='absolute/relative path to the image file')
args = parser.parse_args()
return args
def shred(self,args):
image_path = args.path
SHREDS = 250
image = Image.open(image_path)
# shredded = Image.new("1", image.size)
width, height = image.size
shred_width = width // SHREDS
size = shred_width * SHREDS
shredded = Image.new("RGB", (size, height))
sequence = list(range(0, SHREDS))
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(image_path)
if __name__ == '__main__':
shredder = Shredder();
args = shredder.get_args();
sequence = shredder.shred(args);