From ecec81ead02696a4be80e4dd4c825f03c2d7f24f Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 18 Jul 2024 12:38:05 +1000 Subject: [PATCH] Cast width / height to integer (#7676) * Cast width / height to integer * Convert "rotate" parameter --- .../InvenTree/report/templatetags/report.py | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/backend/InvenTree/report/templatetags/report.py b/src/backend/InvenTree/report/templatetags/report.py index 92fe1408c2..2f04e5464c 100644 --- a/src/backend/InvenTree/report/templatetags/report.py +++ b/src/backend/InvenTree/report/templatetags/report.py @@ -170,6 +170,18 @@ def uploaded_image( width = kwargs.get('width', None) height = kwargs.get('height', None) + if width is not None: + try: + width = int(width) + except ValueError: + width = None + + if height is not None: + try: + height = int(height) + except ValueError: + height = None + if width is not None and height is not None: # Resize the image, width *and* height are provided img = img.resize((width, height)) @@ -185,10 +197,12 @@ def uploaded_image( img = img.resize((wsize, height)) # Optionally rotate the image - rotate = kwargs.get('rotate', None) - - if rotate is not None: - img = img.rotate(rotate) + if rotate := kwargs.get('rotate', None): + try: + rotate = int(rotate) + img = img.rotate(rotate) + except ValueError: + pass # Return a base-64 encoded image img_data = report.helpers.encode_image_base64(img)