This site is developed to XHTML and CSS2 W3C standards.
If you see this paragraph, your browser does not support those standards and you
need to upgrade. Visit WaSP
for a variety of options.
Paste #670
Posted by: BitByByte
Posted on: 2026-04-10 23:58:14
Age: 1 day ago
Views: 6
from PIL import Image
input_file = "INPUT.png" # <--- замените на имя входного файла.
output_file = "OURPUR.png" # <--- замените на имя файла, который получится в результате.
img = Image.open(input_file).convert("RGBA")
r, g, b, a = img.split()
rgb = Image.merge("RGB", (r, g, b))
pal = rgb.convert("P", palette=Image.ADAPTIVE, colors=255)
palette = pal.getpalette()
transparent_color = (255, 0, 255) # если на изображении уже есть подобный цвет, то замените данную переменную на какой-либо другой цвет в формате "(R, G, B)".
palette.extend(transparent_color)
pal.putpalette(palette)
transparent_index = len(palette) // 3 -
mask = a.point(lambda x: 255 if x < 128 else 0)
pal.paste(transparent_index, mask)
pal.info["transparency"] = transparent_index
pal.save(output_file, "PNG")
print("Done!")
Download raw |
Create new paste