mirror of
https://gitlab1.ptb.de/waltem01/Matrix
synced 2024-12-26 03:51:45 +00:00
resize image on client
This commit is contained in:
parent
bc37cb3c67
commit
c4e3d04043
10
API/main.py
10
API/main.py
@ -49,15 +49,12 @@ def display_image():
|
|||||||
|
|
||||||
# receive client data
|
# receive client data
|
||||||
data = request.form
|
data = request.form
|
||||||
# try unpacking image width and height
|
|
||||||
width = int(data.get('w'))
|
|
||||||
height = int(data.get('h'))
|
|
||||||
# try unpacking x,y coordinates
|
# try unpacking x,y coordinates
|
||||||
x_coord = int(data.get('x'))
|
x_coord = int(data.get('x'))
|
||||||
y_coord = int(data.get('y'))
|
y_coord = int(data.get('y'))
|
||||||
|
|
||||||
# call matrix method with data
|
# call matrix method with data
|
||||||
matrix.display_image(x_coord, y_coord, width, height)
|
matrix.display_image(x_coord, y_coord)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# error handling
|
# error handling
|
||||||
print(e)
|
print(e)
|
||||||
@ -295,9 +292,8 @@ class Matrix(SampleBase):
|
|||||||
self.image = Image.open(requests.get(url, stream=True).raw)
|
self.image = Image.open(requests.get(url, stream=True).raw)
|
||||||
|
|
||||||
# display image at position with dimensions in current color
|
# display image at position with dimensions in current color
|
||||||
def display_image(self, x: int, y: int, w: Optional[int] = None, h: Optional[int] = None):
|
def display_image(self, x: int, y: int):
|
||||||
# resize image to specified or max size
|
if self.image is None: return
|
||||||
self.image.resize((w or self.matrix.width, h or self.matrix.height), Image.ANTIALIAS)
|
|
||||||
# set image at position
|
# set image at position
|
||||||
self.canvas.SetImage(self.image, x, y)
|
self.canvas.SetImage(self.image, x, y)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user