Skip to content

Commit 551168c

Browse files
committed
Merge branch 'hotfix/render-palette-images'
[SVCS-819]
2 parents 6389271 + 78f71d2 commit 551168c

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

mfr/extensions/codepygments/render.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def _render_html(self, fp, ext, *args, **kwargs):
6262
content, encoding = None, 'utf-8'
6363
try:
6464
content = data.decode(encoding)
65-
except UnicodeDecodeError as e:
65+
except UnicodeDecodeError:
6666
detected_encoding = chardet.detect(data)
6767
encoding = detected_encoding.get('encoding', None)
6868
if encoding is None:

mfr/extensions/image/export.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ def export(self):
4444
image = image.resize((round(image.size[0] * ratio),
4545
round(image.size[1] * ratio)), Image.ANTIALIAS)
4646

47+
# Mode 'P' is for paletted images. They must be converted to RGB before exporting to
48+
# jpeg, otherwise Pillow will throw an error. This is a temporary workaround, as the
49+
# conversion is imprecise and can be ugly.
50+
# See: https://stackoverflow.com/q/21669657
51+
if image.mode == 'P':
52+
image = image.convert('RGB')
53+
4754
# handle transparency
4855
# from https://github.com/python-pillow/Pillow/issues/2609
4956
if image.mode in ('RGBA', 'RGBa', 'LA') and type in ['jpeg', 'jpg']:

mfr/server/handlers/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def write_error(self, status_code, exc_info):
169169

170170
current['materialized_type'] = '.'.join([x[0] for x in exc.attr_stack])
171171
self.error_metrics = current
172-
except Exception as exc:
172+
except Exception:
173173
pass
174174
self.set_status(exc.code)
175175
self.finish(exc.as_html())

0 commit comments

Comments
 (0)