replace transparent pixels python

Solutions on MaxInterview for replace transparent pixels python by the best coders in the world

showing results for - "replace transparent pixels python"
Yannik
24 Jan 2016
1from PIL import Image
2
3img = Image.open('img.png')
4img = img.convert("RGBA")
5datas = img.getdata()
6
7newData = []
8for item in datas:
9    if item[0] == 255 and item[1] == 255 and item[2] == 255:
10        newData.append((255, 255, 255, 0)) # This is for checking white pixels, replace transparent. Do
11        # if item[3] == 0 to check for transparent pixels.
12    else:
13        newData.append(item)
14
15img.putdata(newData)
16img.save("img2.png", "PNG")