Skip to content

Instantly share code, notes, and snippets.

@ccmorataya
Created October 1, 2019 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccmorataya/3ffb2d74d876493627c44bc5241be1c1 to your computer and use it in GitHub Desktop.
Save ccmorataya/3ffb2d74d876493627c44bc5241be1c1 to your computer and use it in GitHub Desktop.
replace the magenta pixels with transparency
# Original answer in https://stackoverflow.com/a/765774/6189341
from PIL import Image
img = Image.open("area02_level_tiles.png") # CM:: replace area02_level_tiles.png with the name/path of the image to process
img = img.convert("RGBA")
datas = img.getdata()
newData = []
for item in datas:
if item[0] == 255 and item[2] == 255:
newData.append((255, 255, 255, 0))
else:
newData.append(item)
img.putdata(newData)
img.save("transparency.png", "PNG")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment