Skip to content

Commit

Permalink
edits for python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Spyduck committed May 7, 2017
1 parent f968a96 commit 19125de
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions jpglitch.py
@@ -1,9 +1,10 @@
#!/usr/bin/env python3
import io
import copy
import random
import click

from itertools import tee, izip
from itertools import tee
from PIL import Image


Expand All @@ -14,7 +15,7 @@ def pairwise(iterable):
"""
a, b = tee(iterable)
next(b, None)
return izip(a, b)
return zip(a, b)


class Jpeg(object):
Expand Down Expand Up @@ -63,7 +64,7 @@ def glitch_bytes(self):
# bytes around if we glitch it so much we break the file.
new_bytes = copy.copy(self.bytes)

for i in (xrange(iterations)):
for i in (range(iterations)):
max_index = len(self.bytes) - self.header_length - 4

# The following operations determine where we'll overwrite a value
Expand Down Expand Up @@ -110,7 +111,6 @@ def save_image(self, name):
self.parameters['iterations'] -= 1
self.glitch_bytes()


@click.command()
@click.option('--amount', '-a', type=click.IntRange(0, 99, clamp=True),
default=random.randint(0, 99), help="Insert high or low values?")
Expand All @@ -129,7 +129,7 @@ def cli(image, amount, seed, iterations, jpg, output):
jpeg = Jpeg(image_bytes, amount, seed, iterations)

click.echo("\nScrambling your image with the following parameters:")
for key, value in jpeg.parameters.iteritems():
for key, value in jpeg.parameters.items():
click.echo(message=key + ': ' + str(value))

if output:
Expand All @@ -146,3 +146,6 @@ def cli(image, amount, seed, iterations, jpg, output):

output = "\nSucces! Checkout %s." % name
click.echo(output)

if __name__ == '__main__':
cli()

0 comments on commit 19125de

Please sign in to comment.