-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
70 lines (57 loc) · 1.8 KB
/
main.py
File metadata and controls
70 lines (57 loc) · 1.8 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import time
import json
import io
from PIL import Image
class Error(Exception):
"""Base class for other exceptions"""
pass
class sizeDontMatch(Error):
"""error the image size does not match the source"""
pass
class MyCustomError(Exception):
def __init__(self, *args):
if args:
self.message = args[0]
else:
self.message = None
def __str__(self):
print('calling str')
if self.message:
return 'MyCustomError, {0} '.format(self.message)
else:
return 'MyCustomError has been raised'
def getList(dict):
return dict.keys()
def start(args, hkubeapi):
input=args['input'][0]
# print(input)
print("================ data from input ==============")
print(getList(input))
print(input['image.format'])
print(input['image.mode'])
print(input['image.size'])
image = Image.open(io.BytesIO(input['image']))
imgByteArr = io.BytesIO()
image.save(imgByteArr, format=image.format)
result = imgByteArr.getvalue()
print("================ new image ==============")
image.show()
print(image.format)
print(image.mode)
print(image.size)
imgByteArr = io.BytesIO()
image.save(imgByteArr, format=image.format)
result = imgByteArr.getvalue()
W = input['image.size'][0]
L = input['image.size'][1]
if (W,L) != image.size:
raise MyCustomError("not the same size")
#raise sizeDontMatch
time.sleep(2)
return {"name":"convert byte array to image",
"version":"v3-2-webhook",
"image.format":image.format,
"image.mode":image.mode,
"image.size":image.size,
"image":bytearray(result)
}