编译文件不多,一下就完了。步骤如下:
./configure –disable-video –without-qt –without-gtk –without-x –prefix=/usr
make
sudo make install
应该还需要安装ImageMagick,libjpeg-devel,zlib-devel之类的库,python环境里需要安装zbar和PIL。
上测试代码:
import zbar
from PIL import Image
scanner = zbar.ImageScanner()
scanner.parse_config('enable')
img = Image.open('./test.jpg').convert('L')
w, h = img.size
zimg = zbar.Image(w, h, 'Y800', img.tobytes())
scanner.scan(zimg)
for s in zimg:
print s.type, s.data
准备工作首先需要了解二维码,二维码即保存数据的一个容器。微信自己让别人添加好友的二维码同样如此,我们需要把url从微信的二维码中提取出来,在加入到自己准备的背景中。完成~
需要的库
MyQR,pyzbar,PIL (在python 3.0以上版本 不支持zbar,所以我们使用pyzbar)
pip install MyQR
pip install pyzbar
pip install PIL
操作步骤
1、选择自己需要的背景图
2、把原版微信添加好友的二维码保存到手机
3、py文件根目录下创建三个文件夹保存,解析,图片分别在解析和图片中放出2、1、步骤找到的图片
解析
import pyzbar.pyzbar as pyzbar
from PIL import Image
# 打开含有二维码的图片
img = Image.open(r'D:\python\二维码\解析\1.jpg').convert('L')
#获取图片的尺寸
width, height = img.size
print('图片大小:',img.size)
barcodes = pyzbar.decode(img)
for barcode in barcodes:
barcodeData = barcode.data.decode("utf-8")
print(barcodeData)
barcoderect=barcode.rect
qr_size=list(barcoderect)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
运行结果:
图片大小: (1080, 2220)
https://u.wechat.com/IP_UrJFB0Hd6xnFG52eQpAI
制作
代码如下:
from MyQR import myqr
myqr.run(words="https://u.wechat.com/IP_UrJFB0Hd6xnFG52eQpAI",
version=5,
picture=r'D:\\python\\二维码\图片\1.png',
colorized=True,
save_name="33.png",
save_dir="D:\python\二维码\保存")
1
2
3
4
5
6
7
1
2
3
4
5
6
7
等待输出。
我没弄过ubuntu下的graphics.py。但是弄过windows下的。
1. apt是用来安装Ubuntu系统的软件的。
2. Python是Ubuntu下面的一个软件。
3. 而graphics.py属于python中的第三方库函数。
所以,即使用apt,也是用apt去安装,更新python。
而python中的库,有自己的安装方法。
常见的是直接 setup.py install或者用pip之类的去安装。
具体安装的方法,自己去参考这个:
【待完善】【总结】Python安装第三方的库、package的方法
(此处不给贴地址,请用baidu搜标题,即可找到帖子地址)