42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
|
|
import os
|
|
from PIL import Image
|
|
|
|
def add_green_background(image_path):
|
|
try:
|
|
if not os.path.exists(image_path):
|
|
print(f"Skipping {image_path}")
|
|
return
|
|
|
|
# Open image
|
|
img = Image.open(image_path).convert("RGBA")
|
|
|
|
# Create solid green background #00FF00
|
|
green_bg = Image.new("RGBA", img.size, (0, 255, 0, 255))
|
|
|
|
# Composite the image on top of the green background
|
|
# This fills transparent areas with green
|
|
green_bg.alpha_composite(img)
|
|
|
|
# Save back (removing alpha channel to make it fully opaque green if desired,
|
|
# but maintaining format. Usually "chroma key" implies the background is that color).
|
|
# We can save as RGB to discard alpha, ensuring it's solid.
|
|
final = green_bg.convert("RGB")
|
|
|
|
final.save(image_path)
|
|
print(f"Updated with Green BG: {image_path}")
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
|
|
# Files to process (The ones we just cleaned)
|
|
files = [
|
|
"/Users/davidkotnik/repos/novafarma/assets/slike/NOVE_SLIKE/UI/gumb_start.png",
|
|
"/Users/davidkotnik/repos/novafarma/assets/slike/NOVE_SLIKE/UI/merilec_zdravja.png",
|
|
"/Users/davidkotnik/repos/novafarma/assets/slike/NOVE_SLIKE/UI/okvir_zarjavel.png",
|
|
"/Users/davidkotnik/repos/novafarma/assets/slike/NOVE_SLIKE/UI/amnezija_maska.png"
|
|
]
|
|
|
|
for f in files:
|
|
add_green_background(f)
|