forked from ScoDoc/DocScoDoc
Merge pull request 'convert to RGB (from ARGB) when saving as JPEG' (#288) from jmplace/ScoDoc-Lille:fix_rgb_exception into master
Reviewed-on: https://scodoc.org/git/ScoDoc/ScoDoc/pulls/288
This commit is contained in:
commit
f106cbe99f
@ -266,14 +266,16 @@ def _return_logo(name="header", dept_id="", small=False, strict: bool = True):
|
|||||||
suffix = logo.suffix
|
suffix = logo.suffix
|
||||||
if small:
|
if small:
|
||||||
with PILImage.open(logo.filepath) as im:
|
with PILImage.open(logo.filepath) as im:
|
||||||
im.thumbnail(SMALL_SIZE)
|
|
||||||
stream = io.BytesIO()
|
|
||||||
# on garde le même format (on pourrait plus simplement générer systématiquement du JPEG)
|
# on garde le même format (on pourrait plus simplement générer systématiquement du JPEG)
|
||||||
fmt = { # adapt suffix to be compliant with PIL save format
|
fmt = { # adapt suffix to be compliant with PIL save format
|
||||||
"PNG": "PNG",
|
"PNG": "PNG",
|
||||||
"JPG": "JPEG",
|
"JPG": "JPEG",
|
||||||
"JPEG": "JPEG",
|
"JPEG": "JPEG",
|
||||||
}[suffix.upper()]
|
}[suffix.upper()]
|
||||||
|
if fmt == "JPEG":
|
||||||
|
im = im.convert("RGB")
|
||||||
|
im.thumbnail(SMALL_SIZE)
|
||||||
|
stream = io.BytesIO()
|
||||||
im.save(stream, fmt)
|
im.save(stream, fmt)
|
||||||
stream.seek(0)
|
stream.seek(0)
|
||||||
return send_file(stream, mimetype=f"image/{fmt}")
|
return send_file(stream, mimetype=f"image/{fmt}")
|
||||||
|
Loading…
Reference in New Issue
Block a user