mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
* Cast width / height to integer
* Convert "rotate" parameter
(cherry picked from commit ecec81ead0
)
Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
parent
68e2f08fa5
commit
c1d9732e7c
@ -170,6 +170,18 @@ def uploaded_image(
|
|||||||
width = kwargs.get('width', None)
|
width = kwargs.get('width', None)
|
||||||
height = kwargs.get('height', 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:
|
if width is not None and height is not None:
|
||||||
# Resize the image, width *and* height are provided
|
# Resize the image, width *and* height are provided
|
||||||
img = img.resize((width, height))
|
img = img.resize((width, height))
|
||||||
@ -185,10 +197,12 @@ def uploaded_image(
|
|||||||
img = img.resize((wsize, height))
|
img = img.resize((wsize, height))
|
||||||
|
|
||||||
# Optionally rotate the image
|
# Optionally rotate the image
|
||||||
rotate = kwargs.get('rotate', None)
|
if rotate := kwargs.get('rotate', None):
|
||||||
|
try:
|
||||||
if rotate is not None:
|
rotate = int(rotate)
|
||||||
img = img.rotate(rotate)
|
img = img.rotate(rotate)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
# Return a base-64 encoded image
|
# Return a base-64 encoded image
|
||||||
img_data = report.helpers.encode_image_base64(img)
|
img_data = report.helpers.encode_image_base64(img)
|
||||||
|
Loading…
Reference in New Issue
Block a user