BIGBALLON/Crawler_Demo

QRcode

BIGBALLON opened this issue · 0 comments

import qrcode
import os
import pandas as pd
from PIL import Image

file_list = ['1.csv', '2.csv', '3.csv']

def generate_qr_code(url):
    """ Generate a QR Code for the given URL and return an Image file"""
    qr = qrcode.QRCode(
        version=2,
        error_correction=qrcode.constants.ERROR_CORRECT_L,
        box_size=6.2,
        border=3,
    )
    qr.add_data(url)
    qr.make(fit=True)

    return qr.make_image() 

def comblex_pic(base_img, myQR):
    myQR_w, myQR_h = myQR.size
    base_img_w, base_img_h = base_img.size
    sub_x = 110
    sub_y = 135
    paste_location = (base_img_w-myQR_w-sub_x, base_img_h-myQR_h-sub_y, base_img_w-sub_x, base_img_h-sub_y)
    base_img.paste(myQR, paste_location)
    return base_img

def main():
    pic_file = 'pic.jpg'
    pic_count = 1
    base_img = Image.open(pic_file)
    for filename in file_list:
        df=pd.read_csv(filename,usecols=[3],header=None)
        data = df.values[1:]
        print(len(data))
        for url in data:
            print(" == url == :", url)
            qr_img = generate_qr_code(url)
            com_img = comblex_pic(base_img,qr_img)
            com_img.save(str(pic_count) + '.jpg')
            pic_count += 1  
            print(" == done ! == ")

if __name__ == '__main__':
    main()