Spaces:
Paused
Paused
QR code generator
Browse files- DUDE.jpg +0 -0
- make_QR.py +49 -0
DUDE.jpg
ADDED
make_QR.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from PIL import Image
|
2 |
+
import qrcode
|
3 |
+
|
4 |
+
for image, data in zip(
|
5 |
+
# ["dataset", "competition"],
|
6 |
+
# ["https://huggingface.co/datasets/jordyvl/DUDE_loader", "https://rrc.cvc.uab.es/?ch=23"]
|
7 |
+
["dataset1", "dataset2", "code"],
|
8 |
+
[
|
9 |
+
"https://huggingface.co/datasets/bdpc/rvl_cdip_mp",
|
10 |
+
"https://huggingface.co/datasets/bdpc/rvl_cdip_n_mp",
|
11 |
+
"https://huggingface.co/bdpc/src",
|
12 |
+
],
|
13 |
+
):
|
14 |
+
# Create a QR code object
|
15 |
+
qr = qrcode.QRCode(box_size=10, border=4, error_correction=qrcode.constants.ERROR_CORRECT_H) # version=1,
|
16 |
+
|
17 |
+
# Define the data to be encoded in the QR code
|
18 |
+
|
19 |
+
# Add the data to the QR code object
|
20 |
+
qr.add_data(data)
|
21 |
+
|
22 |
+
# Make the QR code
|
23 |
+
qr.make(fit=True)
|
24 |
+
|
25 |
+
# Create an image from the QR code
|
26 |
+
img = qr.make_image(back_color=(255, 254, 255), fill_color=(0, 0, 1))
|
27 |
+
|
28 |
+
# Open the logo or image file
|
29 |
+
|
30 |
+
# remove transparency
|
31 |
+
logo = Image.open(f"{image}.png").convert("RGBA")
|
32 |
+
new_image = Image.new("RGBA", logo.size, "WHITE") # Create a white rgba background
|
33 |
+
new_image.paste(logo, (0, 0), logo) # Paste the image on the background. Go to the links given below for details.
|
34 |
+
new_image.convert("RGB").save(f"{image}.jpg", "JPEG")
|
35 |
+
logo = Image.open(f"{image}.jpg").convert("RGB")
|
36 |
+
|
37 |
+
# Resize the logo or image if needed
|
38 |
+
logo = logo.resize((75, 75))
|
39 |
+
|
40 |
+
# Position the logo or image in the center of the QR code
|
41 |
+
img_w, img_h = img.size
|
42 |
+
logo_w, logo_h = logo.size
|
43 |
+
pos = ((img_w - logo_w) // 2, (img_h - logo_h) // 2)
|
44 |
+
|
45 |
+
# Paste the logo or image onto the QR code
|
46 |
+
img.paste(logo, pos)
|
47 |
+
|
48 |
+
# Save the QR code image with logo or image
|
49 |
+
img.save(f"qr_code_{image}.png")
|