54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
import os
|
|
from PIL import Image, ImageEnhance
|
|
|
|
# Pfade
|
|
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')
|
|
|
|
# Einstellungen zur Bildverbesserung
|
|
# 1.0 ist das Originalbild. 1.3 bedeutet 30% mehr Sättigung.
|
|
SATURATION_FACTOR = 1.4
|
|
CONTRAST_FACTOR = 1.15 # Etwas mehr Kontrast hilft oft bei "blassen" Bildern
|
|
|
|
def process_images():
|
|
if not os.path.exists(OUTPUT_DIR):
|
|
os.makedirs(OUTPUT_DIR)
|
|
print(f"Ordner erstellt: {OUTPUT_DIR}")
|
|
|
|
processed_count = 0
|
|
|
|
# Alle Dateien im Eingangsordner durchlaufen
|
|
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)
|
|
|
|
# Überspringen, falls das Bild schon im Zielordner existiert
|
|
if os.path.exists(output_path):
|
|
continue
|
|
|
|
try:
|
|
with Image.open(input_path) as img:
|
|
# 1. Sättigung anpassen
|
|
enhancer_color = ImageEnhance.Color(img)
|
|
img_enhanced = enhancer_color.enhance(SATURATION_FACTOR)
|
|
|
|
# 2. Kontrast anpassen
|
|
enhancer_contrast = ImageEnhance.Contrast(img_enhanced)
|
|
img_final = enhancer_contrast.enhance(CONTRAST_FACTOR)
|
|
|
|
# Speichern (mit hoher Qualität)
|
|
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} neue Bilder wurden bearbeitet.")
|
|
print(f"Du findest sie hier: {OUTPUT_DIR}")
|
|
|
|
if __name__ == '__main__':
|
|
print("Starte Bildbearbeitung...")
|
|
process_images()
|