Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The purpose of this script is to take an existing image file
- # split it up into a grid and make a stochastic change to each piece
- # then stitch the image back together and save it to a new file
- # future versions will have extra layers of extra types of stochastic changes
- # to defeat censorship, changes must be unpredictable more than they are numerous
- # INSTALL - Only module to install is Pillow, an easy "pip install Pillow" should get you going.
- # USAGE - Install python, save this script as qimg-5.py and image file in same folder.
- # From terminal in the same folder run "python qimg-5.py"
- # you should see the output as well as have a new saved file in the same folder
- # TESTED using python 3.7.1
- import sys
- import random
- from PIL import Image
- # INIT - nothing to change here
- sectors = {}
- xslice = 0
- yslice = 0
- imgslice = {}
- # CONFIG section
- density = 6
- # How small do we want to make the slices, bigger is more. Must be even number
- cornerkiller = 0
- # Set the above to 1 if you want blacked out corners, set it to 0 if you want more mangled corners
- imagefile = "bantest.png"
- # The name of the file you want to convert, must be in same folder as script
- outputfile = "noban"
- # Prefix for the saved file
- # Work starts here, you change it, you break it
- im = Image.open(imagefile)
- res = im.size
- wsize = (int((res[0]) / density))
- hsize = (int((res[1]) / density))
- for h in range(density):
- for i in range(density):
- wslice = (wsize + xslice)
- hslice = (hsize + yslice)
- sector = (xslice, yslice, wslice, hslice)
- sectors[i] = sector
- yslice += hsize
- if (h == 0 and i == 0) or (h == 0 and i + 1 == density) or (h + 1 == density and i == 0) or (h + 1 == density and i + 1 == density):
- imgslice[i] = im.crop(sectors[i]).effect_spread(random.randint(3,5))
- if cornerkiller == 1:
- im.paste('#000000', sectors[i])
- else:
- im.paste(imgslice[i], sectors[i])
- else:
- imgslice[i] = im.crop(sectors[i]).effect_spread(random.randint(1,5))
- im.paste(imgslice[i], sectors[i])
- i = 0
- xslice += wsize
- yslice = 0
- wslice = 0
- hslice = 0
- im.save(outputfile + imagefile)
- im.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement