From 34e7a0fc31a5a51063ad9234c3fb058bf88ae349 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Fri, 23 Jun 2023 11:51:23 +0200 Subject: [PATCH] PDF renderer: Fix crash while embedding iamge (PRETIXEU-8MY) --- src/pretix/base/pdf.py | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/pretix/base/pdf.py b/src/pretix/base/pdf.py index 755e21365..f32438043 100644 --- a/src/pretix/base/pdf.py +++ b/src/pretix/base/pdf.py @@ -860,22 +860,32 @@ class Renderer: image_file = None if image_file: - ir = ThumbnailingImageReader(image_file) try: + ir = ThumbnailingImageReader(image_file) ir.resize(float(o['width']) * mm, float(o['height']) * mm, 300) + canvas.drawImage( + image=ir, + x=float(o['left']) * mm, + y=float(o['bottom']) * mm, + width=float(o['width']) * mm, + height=float(o['height']) * mm, + preserveAspectRatio=True, + anchor='c', # centered in frame + mask='auto' + ) except: - logger.exception("Can not resize image") - pass - canvas.drawImage( - image=ir, - x=float(o['left']) * mm, - y=float(o['bottom']) * mm, - width=float(o['width']) * mm, - height=float(o['height']) * mm, - preserveAspectRatio=True, - anchor='c', # centered in frame - mask='auto' - ) + logger.exception("Can not load or resize image") + canvas.saveState() + canvas.setFillColorRGB(.8, .8, .8, alpha=1) + canvas.rect( + x=float(o['left']) * mm, + y=float(o['bottom']) * mm, + width=float(o['width']) * mm, + height=float(o['height']) * mm, + stroke=0, + fill=1, + ) + canvas.restoreState() else: canvas.saveState() canvas.setFillColorRGB(.8, .8, .8, alpha=1)