需求:
拼接纯二维码到固定背景图片,形成收款码;
特殊要求:
1 张背景图放两张不同二维码
最后效果:
实现:
1. 放置 1 张二维码到背景图片
2. 以上面行形成的背景图,作为背景图,放置第二章二维码
实现一:
#encoding=utf8
import PIL.Image as Image
import os,sys
def join_Pictures(pic_path):
k = 1
for p in pic_path:
qrcode_image = Image.open(p, mode="r")
tmp_image = qrcode_image.resize((630, 630))
base_image = Image.open('/Users/wangqi/taimi/qrcode/base.jpg', mode="r")
box = (92, 324)
base_image.paste(tmp_image, box)
# base_image.show()
base_image.save('/Users/wangqi/taimi/qrcode/tmp_code/%d.jpg' % k)
k+=1
def read_path(path):
paths = []
for root, dirs, files in os.walk(path):
path = [os.path.join(root, name) for name in files]
# print(path)
paths.extend(path)
return paths
if __name__ == '__main__':
pic_path = "/Users/wangqi/taimi/qrcode/qrcode5"
pathss = read_path(pic_path)
join_Pictures(pathss)
实现二:
#encoding=utf8
import PIL.Image as Image
import os,sys
def join_2Pictures(base_path,pic_path):
# 遍历 100 次, 每次从底图和二维码各取一个码拼接
for k in range(100):
# 读取二维码
qrcode_image = Image.open(pic_path[k], mode="r")
# 修改二维码到合适尺寸
tmp_image = qrcode_image.resize((628, 628))
# 读取底图
base_image = Image.open(base_path[k], mode="r")
# 配置粘贴位置
box = (1070, 324)
# 粘贴
base_image.paste(tmp_image, box)
# base_image.show()
# print base_image.mode
# 保存到目标文件夹
base_image.save('/Users/wangqi/taimi/qrcode/codes56/%d.jpg' % k)
k+=1
def read_path(path):
paths = []
for root, dirs, files in os.walk(path):
path = [os.path.join(root, name) for name in files]
# print(path)
paths.extend(path)
return paths
if __name__ == '__main__':
# 二维码
pic_path0 = "/Users/wangqi/taimi/qrcode/qrcode6"
# 底图
base_path = "/Users/wangqi/taimi/qrcode/tmp_code"
# code_path 合成图片保存路径
# code_path = "/Users/wangqi/taimi/qrcode/codes"
paths_code = read_path(pic_path0)
paths_base = read_path(base_path)
join_2Pictures(paths_base, paths_code)