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)
|
# Image processing branch (with caching)
|
||||||
try:
|
try:
|
||||||
with Image.open(full_path) as img:
|
with Image.open(full_path) as img:
|
||||||
img.thumbnail((1200, 1200))
|
img.thumbnail((1920, 1920))
|
||||||
img_bytes = io.BytesIO()
|
if img.mode in ("RGBA", "P"):
|
||||||
img.save(img_bytes, format='PNG', quality=85)
|
img = img.convert("RGB")
|
||||||
img_bytes = img_bytes.getvalue()
|
output_format = 'JPEG'
|
||||||
cache.set(subpath, (img_bytes, mime))
|
output_mime = 'image/jpeg'
|
||||||
response = send_file(io.BytesIO(img_bytes), mimetype=mime, conditional=True)
|
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:
|
except Exception as e:
|
||||||
app.logger.error(f"Image processing failed for {subpath}: {e}")
|
app.logger.error(f"Image processing failed for {subpath}: {e}")
|
||||||
abort(500)
|
abort(500)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user