Advertisement
Guest User

8kun ImageMangler 0.0.2

a guest
Sep 11th, 2020
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.24 KB | None | 0 0
  1. # The purpose of this script is to take an existing image file
  2. # split it up into a grid and make a stochastic change to each piece
  3. # then stitch the image back together and save it to a new file
  4. # future versions will have extra layers of extra types of stochastic changes
  5. # to defeat censorship, changes must be unpredictable more than they are numerous
  6.  
  7. # INSTALL - Only module to install is Pillow, an easy "pip install Pillow" should get you going.
  8. # USAGE - Install python, save this script as qimg-5.py and image file in same folder.
  9. # From terminal in the same folder run "python qimg-5.py"
  10. # you should see the output as well as have a new saved file in the same folder
  11. # TESTED using python 3.7.1
  12.  
  13. import sys
  14. import random
  15. from PIL import Image
  16.  
  17. # INIT - nothing to change here
  18. sectors = {}
  19. xslice = 0
  20. yslice = 0
  21. imgslice = {}
  22.  
  23. # CONFIG section
  24. density = 6
  25. # How small do we want to make the slices, bigger is more. Must be even number
  26.  
  27. cornerkiller = 0
  28. # Set the above to 1 if you want blacked out corners, set it to 0 if you want more mangled corners
  29.  
  30. imagefile = "bantest.png"
  31. # The name of the file you want to convert, must be in same folder as script
  32.  
  33. outputfile = "noban"
  34. # Prefix for the saved file
  35.  
  36. # Work starts here, you change it, you break it
  37.  
  38. im = Image.open(imagefile)
  39. res = im.size
  40.  
  41. wsize = (int((res[0]) / density))
  42. hsize = (int((res[1]) / density))
  43. for h in range(density):
  44.     for i in range(density):
  45.         wslice = (wsize + xslice)
  46.         hslice = (hsize + yslice)
  47.         sector = (xslice, yslice, wslice, hslice)
  48.         sectors[i] = sector
  49.         yslice += hsize
  50.         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):
  51.             imgslice[i] = im.crop(sectors[i]).effect_spread(random.randint(3,5))
  52.             if cornerkiller == 1:
  53.                 im.paste('#000000', sectors[i])
  54.             else:
  55.                 im.paste(imgslice[i], sectors[i])
  56.         else:
  57.             imgslice[i] = im.crop(sectors[i]).effect_spread(random.randint(1,5))
  58.             im.paste(imgslice[i], sectors[i])
  59.     i = 0
  60.     xslice += wsize
  61.     yslice = 0
  62.     wslice = 0
  63.     hslice = 0
  64. im.save(outputfile + imagefile)
  65. im.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement