-
Notifications
You must be signed in to change notification settings - Fork 3
/
util.py
48 lines (40 loc) · 1.06 KB
/
util.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
40
41
42
43
44
45
46
47
48
# coding=utf-8
import time
from io import BytesIO
from PIL import Image
def get_image(source, width=40, height=40, mood=False):
"""
二进制二维码转化为字符串
:param source: 源数据
:param width: 缩放图片大小
:param height: 缩放图片大小
:param mood: false->正常 true->反色
:return:
"""
data = BytesIO()
data.write(source)
image = Image.open(data)
image = image.resize((width, height), Image.NEAREST)
code = ''
for y in range(height):
for x in range(width):
pix = image.getpixel((x, y))
if mood:
if pix < 10:
code += '██'
if pix > 200:
code += ' '
else:
if pix > 200:
code += '██'
if pix < 10:
code += ' '
code += '\n'
return code
def get_time_stamp() -> int:
"""
获得时间戳13位
:return: 时间戳
"""
t = time.time()
return int(round(t * 1000))