File size: 1,785 Bytes
6d90e94
 
 
27a13c3
6d90e94
 
27a13c3
 
 
 
 
 
 
6d90e94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27a13c3
6d90e94
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from PIL import Image
import qrcode

for image, data in zip(["DUDER"], ["https://huggingface.co/spaces/jordyvl/ask_my_thesis"]):
    # ["dataset", "competition"],
    # ["https://huggingface.co/datasets/jordyvl/DUDE_loader", "https://rrc.cvc.uab.es/?ch=23"]
    #     ["dataset1", "dataset2", "code"],
    #     [
    #         "https://huggingface.co/datasets/bdpc/rvl_cdip_mp",
    #         "https://huggingface.co/datasets/bdpc/rvl_cdip_n_mp",
    #         "https://huggingface.co/bdpc/src",
    #     ],
    # ):
    # Create a QR code object
    qr = qrcode.QRCode(box_size=10, border=4, error_correction=qrcode.constants.ERROR_CORRECT_H)  # version=1,

    # Define the data to be encoded in the QR code

    # Add the data to the QR code object
    qr.add_data(data)

    # Make the QR code
    qr.make(fit=True)

    # Create an image from the QR code
    img = qr.make_image(back_color=(255, 254, 255), fill_color=(0, 0, 1))

    # Open the logo or image file

    # remove transparency
    logo = Image.open(f"{image}.png").convert("RGBA")
    new_image = Image.new("RGBA", logo.size, "WHITE")  # Create a white rgba background
    new_image.paste(logo, (0, 0), logo)  # Paste the image on the background. Go to the links given below for details.
    new_image.convert("RGB").save(f"{image}.jpg", "JPEG")
    logo = Image.open(f"{image}.jpg").convert("RGB")

    # Resize the logo or image if needed
    logo = logo.resize((150, 150))

    # Position the logo or image in the center of the QR code
    img_w, img_h = img.size
    logo_w, logo_h = logo.size
    pos = ((img_w - logo_w) // 2, (img_h - logo_h) // 2)

    # Paste the logo or image onto the QR code
    img.paste(logo, pos)

    # Save the QR code image with logo or image
    img.save(f"qr_code_{image}.png")