Files
Nele-Till-Hochzeit/bearbeite_fotos_farben.py

66 lines
2.8 KiB
Python

import os
from PIL import Image, ImageEnhance, ImageOps
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# Neuer Input Ordner von nextgenUp
INPUT_DIR = os.path.join(BASE_DIR, 'media', '20260919_HochzeitNeleTill_NextGenUp')
# Neuer Output Ordner für die komplett fertigen Hochzeitsbilder
OUTPUT_DIR = os.path.join(BASE_DIR, 'media', '20260919_HochzeitNeleTill_Final_Colors')
def process_colors():
if not os.path.exists(INPUT_DIR):
print(f"Fehler: Der Ordner '{INPUT_DIR}' existiert nicht.")
return
if not os.path.exists(OUTPUT_DIR):
os.makedirs(OUTPUT_DIR)
print(f"Zielordner erstellt: {OUTPUT_DIR}")
processed_count = 0
for filename in os.listdir(INPUT_DIR):
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.gif')):
input_path = os.path.join(INPUT_DIR, filename)
output_path = os.path.join(OUTPUT_DIR, filename)
# Wenn die fertige Datei schon existiert, überspringen
if os.path.exists(output_path):
continue
try:
# Wir öffnen das Bild mit RGBA (falls es von NextGenUp als PNG kommt)
with Image.open(input_path) as img:
# Falls es einen Alpha-Kanal hat (PNG), konvertieren wir es zu RGB, um Fehler zu vermeiden
if img.mode in ('RGBA', 'LA') or (img.mode == 'P' and 'transparency' in img.info):
img = img.convert('RGB')
# 1. Auto-Kontrast (Entfernt den Grauschleier)
img_step1 = ImageOps.autocontrast(img, cutoff=1)
# 2. Ganz leichte Aufhellung
img_step2 = ImageEnhance.Brightness(img_step1).enhance(1.08)
# 3. Farbe sanft anheben (um 20%)
img_final = ImageEnhance.Color(img_step2).enhance(1.2)
# Speichern (als PNG, da der Input PNG war, oder als JPG. Hier speichern wir es als das Originalformat)
# Um Platz zu sparen und maximale Kompatibilität zu sichern, speichern wir als JPG
output_jpg_path = os.path.splitext(output_path)[0] + '.jpg'
img_final.save(output_jpg_path, 'JPEG', quality=95)
print(f"Farben optimiert: {filename} -> JPG")
processed_count += 1
except Exception as e:
print(f"Fehler bei {filename}: {e}")
if processed_count > 0:
print(f"\nPerfekt! {processed_count} Bilder haben jetzt starke Farben und tollen Kontrast.")
print(f"Die fertigen Hochzeitsbilder liegen in: {OUTPUT_DIR}")
else:
print("\nKeine neuen Bilder zum Bearbeiten gefunden.")
if __name__ == '__main__':
print("Starte Farb- und Kontrastoptimierung für NextGenUp-Bilder...")
process_colors()