-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_qr_custom.py
More file actions
66 lines (52 loc) · 2.2 KB
/
github_qr_custom.py
File metadata and controls
66 lines (52 loc) · 2.2 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from PIL import Image, ImageDraw, ImageFont
import segno
import os
# === Config ===
github_url = "https://github.com/DialloWill"
logo_path = "github_logo.png"
font_path = "/System/Library/Fonts/Supplemental/Arial Bold.ttf" # Adjust if needed
output_file = "DialloWill_custom_github_qr_animated.gif"
your_name = "DialloWill"
# === Step 1: Create QR Code with transparent background ===
qr_segno = segno.make(github_url, error='h')
qr_segno.save("temp_qr.png", scale=10, dark="#00f2ff", light=None, kind='png')
qr_img = Image.open("temp_qr.png").convert("RGBA")
qr_width, qr_height = qr_img.size
# === Step 2: Load and resize GitHub logo ===
logo = Image.open(logo_path).convert("RGBA")
logo_size = int(qr_width * 0.25)
logo = logo.resize((logo_size, logo_size), Image.LANCZOS)
logo_pos = ((qr_width - logo_size) // 2, (qr_height - logo_size) // 2)
# === Step 3: Load font and prepare name ===
font_size = 32
font = ImageFont.truetype(font_path, font_size)
text_width, text_height = font.getbbox(your_name)[2:]
canvas_height = qr_height + text_height + 20
# === Step 4: Create Animated Frames ===
frames = []
num_frames = 20
start_color = (26, 26, 26)
end_color = (0, 242, 255)
for i in range(num_frames):
# Animate color blend
ratio = i / (num_frames - 1)
r = int(start_color[0] * (1 - ratio) + end_color[0] * ratio)
g = int(start_color[1] * (1 - ratio) + end_color[1] * ratio)
b = int(start_color[2] * (1 - ratio) + end_color[2] * ratio)
# Create gradient background
gradient = Image.new("RGBA", (qr_width, qr_height), (r, g, b, 255))
combined = Image.alpha_composite(gradient, qr_img)
combined.paste(logo, logo_pos, mask=logo)
# Add name text below QR
frame = Image.new("RGBA", (qr_width, canvas_height), (r, g, b, 255))
frame.paste(combined, (0, 0))
draw = ImageDraw.Draw(frame)
text_x = (qr_width - text_width) // 2
text_y = qr_height + 5
draw.text((text_x, text_y), your_name, font=font, fill=(255, 255, 255, 255))
frames.append(frame)
# === Step 5: Save Animated GIF ===
frames[0].save(output_file, save_all=True, append_images=frames[1:], duration=100, loop=0)
# === Cleanup ===
os.remove("temp_qr.png")
print(f"🎉 Animated QR code saved as '{output_file}'")