-
Notifications
You must be signed in to change notification settings - Fork 13
/
NodeServer.py
39 lines (32 loc) · 902 Bytes
/
NodeServer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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)