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()