Search
 
SCRIPT & CODE EXAMPLE
 

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")
Comment

PREVIOUS NEXT
Code Example
Python :: convert a number column into datetime pandas 
Python :: python selenium set attribute of element 
Python :: datetime utcnow 
Python :: finding the index of an item in a pandas df 
Python :: new window selenium python 
Python :: no such table: django_session admin 
Python :: how to read unicode in python 
Python :: rename key in python dictionary 
Python :: python string replace index 
Python :: python permutation 
Python :: rum system commands python 
Python :: how to read text frome another file pythion 
Python :: catch error python 
Python :: python xml replace attribute value 
Python :: get table selenium python pandas 
Python :: python yaml to dict 
Python :: write page source to text file python 
Python :: python warning 
Python :: python size of linked list 
Python :: collections counter 
Python :: python get os 
Python :: create bigram in python 
Python :: python time wait 
Python :: flatten nested list 
Python :: death stranding 
Python :: how to get elasticsearch index list using python 
Python :: normal distribution in python 
Python :: how to close windows in selenium python without quitting the browser 
Python :: assignment 7.1 python data structures 
Python :: how to set breakpoint in python pdb 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =