ujjwalanayal commited on
Commit
8a78da5
·
verified ·
1 Parent(s): eab86ae

Upload 4 files

Browse files
Files changed (4) hide show
  1. git.png +0 -0
  2. github_profile_qr.png +0 -0
  3. main.py +44 -0
  4. requirements.txt +8 -0
git.png ADDED
github_profile_qr.png ADDED
main.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image, ImageDraw, ImageFont
2
+ import qrcode
3
+
4
+ github_url = input("Enter the URL you want to encode in the QR: ").strip()
5
+ username = input("Enter the username to display below the QR: ").strip()
6
+
7
+ qr = qrcode.QRCode(
8
+ error_correction=qrcode.constants.ERROR_CORRECT_H
9
+ )
10
+ qr.add_data(github_url)
11
+ qr.make()
12
+
13
+ img = qr.make_image(fill_color="#0D1117", back_color="white").convert('RGB')
14
+
15
+ logo = Image.open("git.png")
16
+ logo_size = 160
17
+ logo = logo.resize((logo_size, logo_size))
18
+
19
+ qr_width, qr_height = img.size
20
+ logo_pos = ((qr_width - logo_size) // 2, (qr_height - logo_size) // 2)
21
+ img.paste(logo, logo_pos)
22
+
23
+ extra_height = 20
24
+ final_img = Image.new("RGB", (qr_width, qr_height + extra_height), "white")
25
+ final_img.paste(img, (0, 0))
26
+
27
+ draw = ImageDraw.Draw(final_img)
28
+ try:
29
+ font = ImageFont.truetype("tahoma.ttf", 12)
30
+ except:
31
+ font = ImageFont.load_default()
32
+
33
+ text = username
34
+ bbox = draw.textbbox((0, 0), text, font=font)
35
+ text_width = bbox[2] - bbox[0]
36
+ text_height = bbox[3] - bbox[1]
37
+
38
+ text_x = (qr_width - text_width) // 2
39
+ text_y = qr_height + (extra_height - text_height) // 4 - bbox[3]
40
+
41
+ draw.text((text_x, text_y), text, fill="black", font=font)
42
+ final_img.save("github_profile_qr.png")
43
+
44
+ print("✅ GitHub profile QR code saved as github_profile_qr.png")
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # Pillow - Python Imaging Library fork
2
+ # Used for image processing tasks like creating the final QR image,
3
+ # resizing the logo, and adding text below the QR code.
4
+ Pillow==10.0.0
5
+
6
+ # qrcode - QR Code generation library
7
+ # Used to generate the QR code from the given GitHub URL.
8
+ qrcode==7.4.2