本文共 2030 字,大约阅读时间需要 6 分钟。
sudo pip3 install myqr
wget http://labfile.oss.aliyuncs.com/courses/1126/Sources.zipunzip Sources.zip
mkdir .imageio && cd .imageio/imageio/mkdir freeimage && cd freeimagewget http://labfile.oss.aliyuncs.com/courses/1126/libfreeimage-3.16.0-linux64.so
from MyQR import myqrmyqr.run('https://www.baidu.com')quit() words:要编码的文字内容picture:背景图片路径save_name:生成的二维码文件名colorized:是否启用颜色化(默认False)示例:
myqr.run( words='https://www.baidu.com', picture='Sources/baidu.png', colorized=True, save_name='artistic_color.png')
myqr.run( words='https://www.baidu.com', picture='Sources/xxx.gif', colorized=True, save_name='animated.gif')
qrcode/├── LICENSE.md├── README.md├── requirements.txt├── myqr.py└── MyQR/ ├── __init__.py ├── myqr.py └── terminal.py ├── __init__.py └── constants.py ├── data.py ├── ECC.py ├── structure.py ├── matrix.py └── draw.py
MyQR/mylibs/constant.py
MyQR/mylibs/data.py
MyQR/mylibs/ECC.py
MyQR/mylibs/structure.py + matrix.py
MyQR/mylibs/draw.py
MyQR/myqr.py 中 combine() 方法使用 Pillow 库读取并合并图片。
qr = Image.open(qr_name).convert('RGBA') if colorized else qrbg0 = Image.open(bg_name).convert('RGBA')bg0 = ImageEnhance.Contrast(bg0).enhance(contrast)bg0 = ImageEnhance.Brightness(bg0).enhance(brightness) for i in range(qr.size[0]-24): for j in range(qr.size[1]-24): if not ((i in (18,19,20)) or (j in (18,19,20)) or (i<24 and j<24) or (i<24 and j>qr.size[1]-49) or (i>qr.size[0]-49 and j<24) or ((i,j) in aligs) or (i%3==1 and j%3==1) or (bg0.getpixel((i,j))[3]==0)): qr.putpixel((i+12,j+12), bg.getpixel((i,j)))