Files
novafarma/remove_green_bg.py
David Kotnik 61ae6c779d 🎮 Dark-Chibi Noir Demo Scene v1.0 - Kaijev Svet
 Glavne Features:
- Main Demo Scene (main_demo_scene.html) s Kaijem, campfire, trees, tent
- Kai Camp Showcase (kai_camp_showcase.html) - isoliran showcase
- Asset cleanup & transparency fix za vse PNG assete
- Nova struktura: 'assets/slike/nova mapa faza 0-1/'
- Glavne reference v 'assets/slike/glavna_referenca/'

🔧 Technical:
- Python scripts: complete_visual_cleanup.py, remove_green_bg.py
- Transparency fix za vse karakterje, trees, props (brez zelenih ozadij)
- Dokumentacija: TENT_FOUND_REPORT, TRANSPARENCY_FIX_REPORT, VISUAL_CLEANUP_REPORT

🎨 Assets:
- Kai z dreadi (standalone sprite)
- Animated campfire (frame1 + frame2)
- Dead trees (10 variants)
- Tent, grass texture, wood logs
- Full Dark-Chibi Noir aesthetic

🚀 Demo Ready: HTML5 Canvas 2D Scene with WASD movement controls
2026-01-21 22:03:57 +01:00

85 lines
2.4 KiB
Python

#!/usr/bin/env python3
"""
Remove green background from PNG images and make them transparent.
Processes all PNG files in the assets directory recursively.
"""
import os
from PIL import Image
import numpy as np
def remove_green_background(image_path, output_path=None):
"""
Remove green background from an image and make it transparent.
Args:
image_path: Path to input image
output_path: Path to save output (if None, overwrites input)
"""
if output_path is None:
output_path = image_path
# Open image
img = Image.open(image_path)
img = img.convert("RGBA")
# Convert to numpy array
data = np.array(img)
# Get RGB values
red = data[:, :, 0]
green = data[:, :, 1]
blue = data[:, :, 2]
# Define green color range (adjust these values if needed)
# Looking for colors where green is dominant
green_mask = (
(green > 100) & # Green channel is bright
(green > red + 20) & # Green is brighter than red
(green > blue + 20) # Green is brighter than blue
)
# Set alpha to 0 for green pixels
data[:, :, 3][green_mask] = 0
# Create new image
result = Image.fromarray(data, mode="RGBA")
# Save
result.save(output_path, "PNG")
print(f"✓ Processed: {os.path.basename(image_path)}")
return True
def process_directory(directory):
"""Process all PNG files in directory recursively."""
processed_count = 0
for root, dirs, files in os.walk(directory):
for filename in files:
if filename.endswith('.png') and not filename.startswith('.'):
filepath = os.path.join(root, filename)
try:
remove_green_background(filepath)
processed_count += 1
except Exception as e:
print(f"✗ Error processing {filename}: {e}")
return processed_count
if __name__ == "__main__":
assets_dir = "assets/slike/nova mapa faza 0-1"
print("=" * 60)
print("🎨 GREEN BACKGROUND REMOVAL - PNG Transparency Fix")
print("=" * 60)
print(f"\nProcessing directory: {assets_dir}")
print("\nRemoving green backgrounds...\n")
count = process_directory(assets_dir)
print("\n" + "=" * 60)
print(f"✅ COMPLETE: Processed {count} PNG files")
print("=" * 60)