Advertisement
Guest User

Script for generating glitched gifs for Lepra

a guest
Aug 4th, 2015
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.28 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Tue Aug  4 12:45:45 2015
  4.  
  5. @author: god
  6. """
  7.  
  8. import textwrap
  9. import random
  10. import subprocess
  11. import jpglitch
  12. import click
  13. import PIL
  14. from PIL import ImageFont
  15. from PIL import Image
  16. from PIL import ImageDraw
  17. import numpy as np
  18.  
  19. def glitch_the_body(body, amount, iterations):
  20.     # font = ImageFont.truetype("Arial-Bold.ttf",14)
  21.    
  22.     wrapped_text = []
  23.     for line in body.splitlines():
  24.         wrapped_text.extend(textwrap.wrap(line, width=60))
  25.     numlines = len([line for line in wrapped_text])
  26.     img=Image.new("RGBA", (450,17*numlines),(255,255,255))
  27.     font = ImageFont.truetype("verdana.ttf", 12, encoding='utf-8')
  28.     draw = ImageDraw.Draw(img)
  29.     margin = 1
  30.     offset = 0
  31.     for line in wrapped_text:
  32.         draw.text((margin,offset), line, font=font, fill="#000000")
  33.         offset += 17
  34.    
  35.     img.save("D:/Not/Gonna/Tell/Myfolder/glitchimgs/1.jpg")
  36.    
  37.     dirpath = "D:\\Not\\Gonna\\Tell\\Myfolder\\glitchimgs\\"
  38.     infile = "D:/Not/Gonna/Tell/Myfolder/glitchimgs/1.jpg"
  39.     for i in range(4):
  40.         seed = np.random.randint(0, 99)
  41.         with open(infile, 'rb') as input_file:
  42.             try:
  43.                 jpglitch.cli(input_file, amount, seed, iterations, False, dirpath + '1_{0}'.format(i))
  44.             except click.exceptions.BadParameter:
  45.                 print('Image is beyond repair. Trying again.')
  46.                 jpglitch.cli(input_file, amount, seed, iterations, False, dirpath + '1_{0}'.format(i))
  47.                
  48.    
  49.     path_to_imagemagick = "C:\Program Files\ImageMagick-6.9.1-Q16\convert.exe"
  50.     outfile_name = str('%030x' % random.randrange(16**30)) + '.gif'
  51.     path_to_outfile = dirpath + outfile_name
  52.     what_to_run = '{0} -delay {1} -loop 0 {2} -delay {3} {4} -delay {5} {6} -delay {7} {8} -delay {9} {10} {11}'.\
  53.         format(
  54.             path_to_imagemagick,
  55.             np.random.randint(100),
  56.             dirpath + '1_0.png',
  57.             np.random.randint(100),
  58.             dirpath + '1_1.png',
  59.             np.random.randint(100),
  60.             dirpath + '1_2.png',
  61.             np.random.randint(100),
  62.             dirpath + '1_3.png',
  63.             50+np.random.randint(50),
  64.             dirpath + '1.jpg',
  65.             path_to_outfile)
  66.     subprocess.check_call(what_to_run)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement