Python (or anything else vaguely sensible) - image conversion to monochrome.
Go to solution
Solved by pythonmegapixel,
Using various responses from this thread and elsewhere, I've managed to cobble together a solution in Python using Pillow. I thought I'd just put my code here incase it helps anyone else:
from PIL import Image import glob for f in glob.glob("./png/*.png"): img = Image.open(f) pixels = img.load() size = img.size for w in range(size[0]): for h in range(size[1]): if pixels[w,h][3] > 0: # If the alpha channel is more than zero (i.e. is partially or fully transparent) pixels [w,h] = (0, 0, 0, 255) # Set to black, fully opaque else: pixels [w,h] = (0,0,0,0) # Set to fully transparent img.save(f + "_BLACK.png")
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now