Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- exempt_cols = ['a9a9a9',
- '4f4f4f',
- '556e5c',
- '000000',
- 'fa8e8e',
- 'cd6060',
- 'ca1d1d',
- 'f96969']
- def to_hex(r, g, b, a=255):
- return hex(r)[2:4] + hex(g)[2:4] + hex(b)[2:4]
- img = Image.open('king.png')
- imga = img.convert("RGB")
- pixels = imga.getdata()
- new_data = []
- for pixel in pixels:
- if to_hex(*pixel) in exempt_cols:
- print to_hex(*pixel)
- new_data.append(pixel)
- else:
- new_data.append((255, 255, 255, 0))
- img.putdata(new_data)
- img.save("filteredking.png", "PNG")
Advertisement
Add Comment
Please, Sign In to add comment