Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

replace transparent pixels python

from PIL import Image

img = Image.open('img.png')
img = img.convert("RGBA")
datas = img.getdata()

newData = []
for item in datas:
    if item[0] == 255 and item[1] == 255 and item[2] == 255:
        newData.append((255, 255, 255, 0)) # This is for checking white pixels, replace transparent. Do
        # if item[3] == 0 to check for transparent pixels.
    else:
        newData.append(item)

img.putdata(newData)
img.save("img2.png", "PNG")
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #replace #transparent #pixels #python
ADD COMMENT
Topic
Name
5+9 =