62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
import os
|
|
from PIL import Image
|
|
from pathlib import Path
|
|
|
|
def convert_debug_images():
|
|
debug_base = Path('debug_images')
|
|
images_base = Path('images')
|
|
|
|
if not debug_base.exists():
|
|
print(f"Fehler: {debug_base} existiert nicht")
|
|
return
|
|
|
|
# Alle Unterordner in debug_images durchlaufen
|
|
for root, dirs, files in os.walk(debug_base):
|
|
current_dir = Path(root)
|
|
relative_path = current_dir.relative_to(debug_base)
|
|
dest_dir = images_base / relative_path
|
|
|
|
# Prüfen ob original.png existiert
|
|
if 'original.png' not in files:
|
|
continue
|
|
|
|
# Zielverzeichnis erstellen
|
|
dest_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
# Pfade definieren
|
|
png_path = current_dir / 'original.png'
|
|
webp_path = dest_dir / 'original.webp'
|
|
thumb_path = dest_dir / 'thumbnail.webp'
|
|
|
|
try:
|
|
# Originalbild öffnen und konvertieren
|
|
with Image.open(png_path) as img:
|
|
# Konvertierung zu RGB falls notwendig
|
|
if img.mode in ('RGBA', 'LA'):
|
|
img = img.convert('RGB')
|
|
|
|
# Original als WebP speichern
|
|
img.save(
|
|
webp_path,
|
|
'WEBP',
|
|
quality=50,
|
|
method=6 # Qualitätsoptimierung
|
|
)
|
|
print(f"Konvertiert: {webp_path}")
|
|
|
|
# Thumbnail erstellen
|
|
img.thumbnail((256, 256), resample=Image.LANCZOS)
|
|
img.save(
|
|
thumb_path,
|
|
'WEBP',
|
|
quality=50,
|
|
method=6
|
|
)
|
|
print(f"Thumbnail erstellt: {thumb_path}")
|
|
|
|
except Exception as e:
|
|
print(f"Fehler bei {png_path}: {str(e)}")
|
|
|
|
if __name__ == '__main__':
|
|
convert_debug_images()
|
|
print("Konvertierung abgeschlossen") |