convert images to jpeg only
This commit is contained in:
parent
b8d760047e
commit
f57db40e4f
18
app.py
18
app.py
@ -222,12 +222,18 @@ def serve_file(subpath):
|
||||
# Image processing branch (with caching)
|
||||
try:
|
||||
with Image.open(full_path) as img:
|
||||
img.thumbnail((1200, 1200))
|
||||
img_bytes = io.BytesIO()
|
||||
img.save(img_bytes, format='PNG', quality=85)
|
||||
img_bytes = img_bytes.getvalue()
|
||||
cache.set(subpath, (img_bytes, mime))
|
||||
response = send_file(io.BytesIO(img_bytes), mimetype=mime, conditional=True)
|
||||
img.thumbnail((1920, 1920))
|
||||
if img.mode in ("RGBA", "P"):
|
||||
img = img.convert("RGB")
|
||||
output_format = 'JPEG'
|
||||
output_mime = 'image/jpeg'
|
||||
save_kwargs = {'quality': 85}
|
||||
|
||||
img_bytes_io = io.BytesIO()
|
||||
img.save(img_bytes_io, format=output_format, **save_kwargs)
|
||||
thumb_bytes = img_bytes_io.getvalue()
|
||||
cache.set(subpath, (thumb_bytes, output_mime))
|
||||
response = send_file(io.BytesIO(thumb_bytes), mimetype=output_mime, conditional=True)
|
||||
except Exception as e:
|
||||
app.logger.error(f"Image processing failed for {subpath}: {e}")
|
||||
abort(500)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user