From 19125dede8289f08f3abfe78492ba0ed331ea69f Mon Sep 17 00:00:00 2001 From: Spyduck Date: Sun, 7 May 2017 18:25:04 -0400 Subject: [PATCH] edits for python 3 --- jpglitch.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/jpglitch.py b/jpglitch.py index 24be38e..fb0d7d9 100644 --- a/jpglitch.py +++ b/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 @@ -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): @@ -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 @@ -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?") @@ -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: @@ -146,3 +146,6 @@ def cli(image, amount, seed, iterations, jpg, output): output = "\nSucces! Checkout %s." % name click.echo(output) + +if __name__ == '__main__': + cli() \ No newline at end of file