49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
import os
|
|
from PIL import Image, ImageEnhance, ImageOps
|
|
|
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
INPUT_DIR = os.path.join(BASE_DIR, 'media', 'Schnappix')
|
|
OUTPUT_DIR = os.path.join(BASE_DIR, 'media', 'Schnappix_Bearbeitet')
|
|
|
|
def process_images():
|
|
if not os.path.exists(OUTPUT_DIR):
|
|
os.makedirs(OUTPUT_DIR)
|
|
print(f"Ordner 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)
|
|
|
|
if os.path.exists(output_path):
|
|
continue
|
|
|
|
try:
|
|
with Image.open(input_path) as img:
|
|
# Der bewährte Mix aus Option 1 und 4:
|
|
|
|
# 1. Auto-Kontrast (Entfernt den Grauschleier)
|
|
img_step1 = ImageOps.autocontrast(img, cutoff=1)
|
|
|
|
# 2. Ganz leichte Aufhellung (damit es nicht zu dunkel wird)
|
|
img_step2 = ImageEnhance.Brightness(img_step1).enhance(1.08)
|
|
|
|
# 3. Farbe leicht anheben (1.2 statt den extremen 1.4 vom allerersten Versuch)
|
|
img_final = ImageEnhance.Color(img_step2).enhance(1.2)
|
|
|
|
# Speichern
|
|
img_final.save(output_path, quality=95)
|
|
print(f"Bearbeitet: {filename}")
|
|
processed_count += 1
|
|
except Exception as e:
|
|
print(f"Fehler bei {filename}: {e}")
|
|
|
|
print(f"\nFertig! {processed_count} Bilder wurden bearbeitet.")
|
|
print(f"Du findest sie hier: {OUTPUT_DIR}")
|
|
|
|
if __name__ == '__main__':
|
|
print("Starte finale Bildbearbeitung...")
|
|
process_images()
|