Simple exemple de code python que j'ai développé pour rendre l'arrière-fond d'une image transparent (image utilisée open-science-logo.png).
<!DOCTYPE html>
<html lang="en">
<body style="background-color: #3c3d41;">
<img src="open_science_logo.png" style="width:500px;margin: 200px 500px;">
</body>
</html>
Code python utilisant le module PILLOW
from PIL import Image
img = Image.open('open_science_logo.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))
else:
if item[0] > 150:
newData.append((0, 0, 0, 255))
else:
newData.append(item)
print(item)
img.putdata(newData)
img.save("open_science_logo_transparent.png", "PNG")
Références
Links | Site |
---|---|
How to merge a transparent png image with another image using PIL | stackoverflow |
Using PIL to make all white pixels transparent? | stackoverflow |
HTML PNG image transparent | stackoverflow |
How to convert the background to transparent? [closed] | stackoverflow |
Using the Right Logo Image – Transparent PNG | stackoverflow |
How to Make a Transparent PNG | stackoverflow |
How to paste a PNG image with transparency to another image in PIL without white pixels? | stackoverflow |
lunapic | stackoverflow |
Make the background of an image transparent in under two minutes on a Mac | stackoverflow |
How to Make Transparent Images with Preview in OS X | stackoverflow |
HTML background color | w3schools |