[770c98]: / Docs / _static / Cool_Guy / alpha.py

Download this file

17 lines (14 with data), 440 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
"""
A simple script for transforming the green
pixels in an image into alpha pixels (transparent).
The gray scale channel is transformed into
alpha channel.
"""
from PIL import Image
image = Image.open("input.png").convert('RGBA')
pixeldata = list(image.getdata())
for i,pixel in enumerate(pixeldata):
if pixel[:3] == (0,255,0):
pixeldata[i] = (255,255,255,0)
image.putdata(pixeldata)
image.save("output.png")