From 6fcfd2a644d520e8e852a718bfaa2c5cfd9eff08 Mon Sep 17 00:00:00 2001 From: vexilligera Date: Mon, 12 Nov 2018 12:46:00 +0800 Subject: [PATCH] Create NodeServer.py --- NodeServer.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 NodeServer.py diff --git a/NodeServer.py b/NodeServer.py new file mode 100644 index 0000000..475a5af --- /dev/null +++ b/NodeServer.py @@ -0,0 +1,39 @@ +import requests +import re +import time +import base64 +import subprocess +from io import BytesIO +from PIL import Image + +class Draw: + def setUrl(self, url): + self.url = url + + def setSize(self, width, height): + self.width = width + self.height = height + api = self.url + '/setsize/%d/%d' % (width, height) + r = requests.get(api) + + def setRadius(self, radius): + api = self.url + '/setradius/%f' % (radius) + r = requests.get(api) + + def setColor(self, color): + api = self.url + '/setcolor/%f/%f/%f' % (color[0], color[1], color[2]) + r = requests.get(api) + + def stroke(self, array): + api = self.url + '/stroke' + r = requests.post(api, json=array) + + def getImage(self): + api = self.url + '/getimage' + r = requests.get(api) + data = re.sub('^data:image/.+;base64,', '', r.text) + return Image.open(BytesIO(base64.b64decode(data))) + + def close(self): + api = self.url + '/close' + r = requests.get(api)