diff options
author | AL-LCL <alvin@alvinhavel.com> | 2023-05-19 11:01:49 +0200 |
---|---|---|
committer | AL-LCL <alvin@alvinhavel.com> | 2023-05-19 11:01:49 +0200 |
commit | 20dbeb2f38684c65ff0a4b99012c161295708e88 (patch) | |
tree | a5b8445f55da2fbbb92443b68e9d7354a290c598 /foreign/client_handling/image.py |
Diffstat (limited to 'foreign/client_handling/image.py')
-rw-r--r-- | foreign/client_handling/image.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/foreign/client_handling/image.py b/foreign/client_handling/image.py new file mode 100644 index 0000000..1ed406d --- /dev/null +++ b/foreign/client_handling/image.py @@ -0,0 +1,26 @@ +import cv2 + +from desktopmagic.screengrab_win32 import getDisplayRects, getRectAsImage +from PIL import Image + + +def image(image_type, monitor): + if image_type: + screenshot = getRectAsImage(getDisplayRects()[monitor]) + + return {'message': 'Screenshot successfully captured', 'screenshot': screenshot, 'text_mode': 'success'} + elif not image_type: + cam = cv2.VideoCapture(monitor) + + check, frame = cam.read() + if not check: + raise Exception('Cam unavailable') + + frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) + frame = Image.fromarray(frame) + + cam.release() + + return {'message': 'Cam screenshot successfully captured', 'screenshot': frame, 'text_mode': 'success'} + else: + raise Exception('Error message')
\ No newline at end of file |