Guest User

Untitled

a guest
Jan 12th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. from PIL import Image
  2.  
  3. exempt_cols = ['a9a9a9',
  4.                '4f4f4f',
  5.                '556e5c',
  6.                '000000',
  7.                'fa8e8e',
  8.                'cd6060',
  9.                'ca1d1d',
  10.                'f96969']
  11.  
  12.  
  13. def to_hex(r, g, b, a=255):
  14.     return hex(r)[2:4] + hex(g)[2:4] + hex(b)[2:4]
  15.  
  16. img = Image.open('king.png')
  17. imga = img.convert("RGB")
  18.  
  19. pixels = imga.getdata()
  20.  
  21. new_data = []
  22. for pixel in pixels:
  23.     if to_hex(*pixel) in exempt_cols:
  24.         print to_hex(*pixel)
  25.         new_data.append(pixel)
  26.     else:
  27.         new_data.append((255, 255, 255, 0))
  28.  
  29. img.putdata(new_data)
  30. img.save("filteredking.png", "PNG")
Advertisement
Add Comment
Please, Sign In to add comment