From c1d9732e7c3460d1fe413402f6f06021ecb50778 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 18 Jul 2024 12:47:44 +1000 Subject: [PATCH] Cast width / height to integer (#7676) (#7677) * Cast width / height to integer * Convert "rotate" parameter (cherry picked from commit ecec81ead02696a4be80e4dd4c825f03c2d7f24f) Co-authored-by: Oliver --- .../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 aea2105abb..7ef89cfdba 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)