Python制作金钱豹收款码表情包

Python制作金钱豹收款码表情包_第1张图片 

 

源码: 

import os
import qrcode
from pyzbar import pyzbar
from PIL import Image
 
#收款码地址
img_adds='C:/Users/73152/Desktop/test/code.jpg'
os.path.isfile(img_adds)
img = Image.open(img_adds)
 
# 显示图片,测试用
img.show()
 
txt_list = pyzbar.decode(img)
 
for txt in txt_list:
    barcodeData = txt.data.decode("utf-8")
    print(barcodeData)
 
img = qrcode.make(barcodeData)
#生成的二维码图片地址
img.save('C:/Users/73152/Desktop/test/simpleqrcode.jpg')
 
def Picture_Synthesis():
    """
    :param mother_img: 母图
    :param son_img: 子图
    :param save_img: 保存图片名
    :param coordinate: 子图在母图的坐标
    :return:
    """
    img_nums=input("请输入编号1-9")
    #金钱豹收款码地址
    mother_img = 'C:/Users/73152/Desktop/test/%s.jpg' % img_nums
    # 生成的二维码图片地址
    son_img = 'C:/Users/73152/Desktop/test/simpleqrcode.jpg'
    #保存的金钱豹收款码地址
    save_img = 'C:/Users/73152/Desktop/test/codes.jpg'
    coordinate = (485,815)
    #将图片赋值,方便后面的代码调用
    M_Img = Image.open(mother_img)
    S_Img = Image.open(son_img)
    factor = 3.5#子图缩小的倍数1代表不变,2就代表原来的一半
 
    #给图片指定色彩显示格式
    M_Img = M_Img.convert("RGB")  # CMYK/RGBA 转换颜色格式(CMYK用于打印机的色彩,RGBA用于显示器的色彩)
 
    # 获取图片的尺寸
    M_Img_w, M_Img_h = M_Img.size  # 获取被放图片的大小(母图)
    print("母图尺寸:",M_Img.size)
    S_Img_w, S_Img_h = S_Img.size  # 获取小图的大小(子图)
    print("子图尺寸:",S_Img.size)
 
    size_w = int(S_Img_w / factor)
    size_h = int(S_Img_h / factor)
 
    # 防止子图尺寸大于母图
    if S_Img_w > size_w:
        S_Img_w = size_w
    if S_Img_h > size_h:
        S_Img_h = size_h
 
    # # 重新设置子图的尺寸
    # icon = S_Img.resize((S_Img_w, S_Img_h), Image.ANTIALIAS)
    icon = S_Img.resize((S_Img_w, S_Img_h), Image.ANTIALIAS)
    w = int((M_Img_w - S_Img_w) / 2)
    h = int((M_Img_h - S_Img_h) / 2)
 
    try:
        if coordinate==None or coordinate=="":
            coordinate=(w, h)
            # 粘贴子图到母图的指定坐标(当前居中)
            M_Img.paste(icon, coordinate, mask=None)
        else:
            print("已经指定坐标")
            # 粘贴子图到母图的指定坐标(当前居中)
            M_Img.paste(icon, coordinate, mask=None)
    except:
        print("坐标指定出错 ")
    # 保存图片
    M_Img.save(save_img)
    M_Img.show()
 
Picture_Synthesis()

你可能感兴趣的:(Python,python,开发语言,后端)