PDF renderer: Fix crash while embedding iamge (PRETIXEU-8MY)

This commit is contained in:
Raphael Michel
2023-06-23 11:51:23 +02:00
parent cc7f249cb8
commit 34e7a0fc31

View File

@@ -860,12 +860,9 @@ class Renderer:
image_file = None image_file = None
if image_file: if image_file:
ir = ThumbnailingImageReader(image_file)
try: try:
ir = ThumbnailingImageReader(image_file)
ir.resize(float(o['width']) * mm, float(o['height']) * mm, 300) ir.resize(float(o['width']) * mm, float(o['height']) * mm, 300)
except:
logger.exception("Can not resize image")
pass
canvas.drawImage( canvas.drawImage(
image=ir, image=ir,
x=float(o['left']) * mm, x=float(o['left']) * mm,
@@ -876,6 +873,19 @@ class Renderer:
anchor='c', # centered in frame anchor='c', # centered in frame
mask='auto' mask='auto'
) )
except:
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: else:
canvas.saveState() canvas.saveState()
canvas.setFillColorRGB(.8, .8, .8, alpha=1) canvas.setFillColorRGB(.8, .8, .8, alpha=1)