-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeGenerator.py
36 lines (31 loc) · 1.01 KB
/
CodeGenerator.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
from barcode import Code128
from barcode.writer import ImageWriter
import qrcode
class CodeGenerator:
def create_barcode(self, text):
"""
在other文件夹中创建名为barcode.png的条形码图片
:param number: 输入的文本
:return: 图片的相对路径
"""
my_code = Code128(text, writer=ImageWriter())
my_code.save("./other/barcode")
return "./other/barcode.png"
def create_QRcode(self, text):
"""
在other文件夹中创建名为QRcode.png的二维码图片
:param text: 输入的文本/链接
:return: 图片的相对路径
"""
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(text)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
pic_path = './other/QRcode.png'
img.save(pic_path)
return pic_path