Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python
- from PIL import Image
- from random import randint
- # Sorts img kinda randomly
- source = Image.open("test.jpg")
- threshold = 150
- img = source.load()
- blackandwhite = source.convert("L").load()
- canvas = Image.new("RGB", source.size)
- newimg = canvas.load()
- count = source.size[0]
- print (source.format)
- print (source.size)
- print (source.mode)
- print ("Threshold: ", threshold)
- print ("============================================")
- counter = 0 #counter
- # do the loop twice because we want to make em fall!
- counter = 0
- for i in range(0, source.size[0]-1): # loop through every x value
- vert_list = [] #list of this column
- for pix in range(0, source.size[1]-1): #make a list of the column from the b&w img
- #store greyscale-color pixel pairs
- grey = blackandwhite[i, pix] #for being in color ^^
- color = img[i, pix]
- vert_list.append((grey, color))
- counter += 1
- if counter % 10 == 0:
- print(counter, "/", count)
- #now remove all pixels brighter than the threshold
- #each x is a greyscale-color pair, so x[0] is the greyscale value
- vert_list[:] = (x for x in vert_list if threshold > x[0])
- top_spacing = source.size[1] - len(vert_list) #height
- for pixel in range(0, len(vert_list)):
- #each vert_list[pixel] is a greyscale-color pair, so its [1] is the color
- newimg[i,pixel + top_spacing] = vert_list[pixel][1]
- canvas.save("fall.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement