Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Tue Aug 4 12:45:45 2015
- @author: god
- """
- import textwrap
- import random
- import subprocess
- import jpglitch
- import click
- import PIL
- from PIL import ImageFont
- from PIL import Image
- from PIL import ImageDraw
- import numpy as np
- def glitch_the_body(body, amount, iterations):
- # font = ImageFont.truetype("Arial-Bold.ttf",14)
- wrapped_text = []
- for line in body.splitlines():
- wrapped_text.extend(textwrap.wrap(line, width=60))
- numlines = len([line for line in wrapped_text])
- img=Image.new("RGBA", (450,17*numlines),(255,255,255))
- font = ImageFont.truetype("verdana.ttf", 12, encoding='utf-8')
- draw = ImageDraw.Draw(img)
- margin = 1
- offset = 0
- for line in wrapped_text:
- draw.text((margin,offset), line, font=font, fill="#000000")
- offset += 17
- img.save("D:/Not/Gonna/Tell/Myfolder/glitchimgs/1.jpg")
- dirpath = "D:\\Not\\Gonna\\Tell\\Myfolder\\glitchimgs\\"
- infile = "D:/Not/Gonna/Tell/Myfolder/glitchimgs/1.jpg"
- for i in range(4):
- seed = np.random.randint(0, 99)
- with open(infile, 'rb') as input_file:
- try:
- jpglitch.cli(input_file, amount, seed, iterations, False, dirpath + '1_{0}'.format(i))
- except click.exceptions.BadParameter:
- print('Image is beyond repair. Trying again.')
- jpglitch.cli(input_file, amount, seed, iterations, False, dirpath + '1_{0}'.format(i))
- path_to_imagemagick = "C:\Program Files\ImageMagick-6.9.1-Q16\convert.exe"
- outfile_name = str('%030x' % random.randrange(16**30)) + '.gif'
- path_to_outfile = dirpath + outfile_name
- what_to_run = '{0} -delay {1} -loop 0 {2} -delay {3} {4} -delay {5} {6} -delay {7} {8} -delay {9} {10} {11}'.\
- format(
- path_to_imagemagick,
- np.random.randint(100),
- dirpath + '1_0.png',
- np.random.randint(100),
- dirpath + '1_1.png',
- np.random.randint(100),
- dirpath + '1_2.png',
- np.random.randint(100),
- dirpath + '1_3.png',
- 50+np.random.randint(50),
- dirpath + '1.jpg',
- path_to_outfile)
- subprocess.check_call(what_to_run)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement