From bd179dec97f03eb7870f5cf57e1d97835876dc0b Mon Sep 17 00:00:00 2001 From: Maciej Pienczyn Date: Wed, 8 Apr 2026 14:28:11 +0200 Subject: [PATCH] fix(company): convert uploaded logos to .webp so templates display them Templates expect logo at {slug}.webp with SVG fallback. When users uploaded JPG/PNG files, the logo was saved with original extension and never displayed. Now all raster uploads are converted to .webp via Pillow; SVG stays as-is. Co-Authored-By: Claude Opus 4.6 (1M context) --- blueprints/public/routes_company_edit.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/blueprints/public/routes_company_edit.py b/blueprints/public/routes_company_edit.py index aa8f45a..49ee76c 100644 --- a/blueprints/public/routes_company_edit.py +++ b/blueprints/public/routes_company_edit.py @@ -237,12 +237,12 @@ def _save_description(db, company): else: company.category_id = None - # Logo upload — save as static/img/companies/{slug}.{ext} - # company_detail.html expects logo at this path with webp→svg fallback + # Logo upload — always convert to .webp (templates expect {slug}.webp) logo_file = request.files.get('logo_file') if logo_file and logo_file.filename: import os - from werkzeug.utils import secure_filename + from PIL import Image + import io allowed = {'png', 'jpg', 'jpeg', 'svg', 'webp'} ext = logo_file.filename.rsplit('.', 1)[-1].lower() if '.' in logo_file.filename else '' @@ -254,8 +254,14 @@ def _save_description(db, company): old_path = os.path.join(logo_dir, f"{company.slug}.{old_ext}") if os.path.exists(old_path): os.remove(old_path) - filepath = os.path.join(logo_dir, f"{company.slug}.{ext}") - logo_file.save(filepath) + filepath = os.path.join(logo_dir, f"{company.slug}.webp") + if ext == 'svg': + # SVG stays as-is (can't convert to webp) + filepath = os.path.join(logo_dir, f"{company.slug}.svg") + logo_file.save(filepath) + else: + img = Image.open(logo_file) + img.save(filepath, 'WEBP', quality=85) logger.info(f"Logo uploaded for company {company.id}: {filepath}")