Skip to content

Commit

Permalink
Cast width / height to integer (#7676)
Browse files Browse the repository at this point in the history
* Cast width / height to integer

* Convert "rotate" parameter

(cherry picked from commit ecec81e)
  • Loading branch information
SchrodingersGat committed Jul 18, 2024
1 parent 68e2f08 commit 57accbb
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/backend/InvenTree/report/templatetags/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down

0 comments on commit 57accbb

Please sign in to comment.