Files
Krzak.org/generate_bgs.py
T
2026-07-07 08:04:07 +02:00

76 lines
2.4 KiB
Python

from PIL import Image, ImageDraw
def hex_to_rgb(hex_code):
hex_code = hex_code.lstrip('#')
return tuple(int(hex_code[i:i+2], 16) for i in (0, 2, 4))
# 1. Vertical Gradient
h = 2000
img = Image.new('RGB', (1, h))
draw = ImageDraw.Draw(img)
color_top = hex_to_rgb('#1a1130')
color_bottom = hex_to_rgb('#120d22')
for y in range(h):
r = int(color_top[0] + (color_bottom[0] - color_top[0]) * (y / h))
g = int(color_top[1] + (color_bottom[1] - color_top[1]) * (y / h))
b = int(color_top[2] + (color_bottom[2] - color_top[2]) * (y / h))
draw.point((0, y), fill=(r, g, b))
img.save('bg_gradient.png')
# 2. Top-Left and Top-Right Glows (Large image, say 2000x800)
w_glow, h_glow = 2000, 800
img_glow = Image.new('RGBA', (w_glow, h_glow), (0, 0, 0, 0))
draw_glow = ImageDraw.Draw(img_glow)
# Top left glow: #e0a05b 8% opacity, transparent at 28%
# Top right glow: #8b4789 18% opacity, transparent at 30%
# We'll just approximate it.
center_left = (0, 0)
radius_left = 600
center_right = (2000, 0)
radius_right = 650
for y in range(h_glow):
for x in range(w_glow):
# Left
dist_left = ((x - center_left[0])**2 + (y - center_left[1])**2)**0.5
alpha_left = 0
if dist_left < radius_left:
alpha_left = int(255 * 0.08 * (1 - dist_left / radius_left))
# Right
dist_right = ((x - center_right[0])**2 + (y - center_right[1])**2)**0.5
alpha_right = 0
if dist_right < radius_right:
alpha_right = int(255 * 0.18 * (1 - dist_right / radius_right))
r, g, b, a = 0, 0, 0, 0
if alpha_left > alpha_right:
r, g, b, a = 224, 160, 91, alpha_left
elif alpha_right > 0:
r, g, b, a = 139, 71, 137, alpha_right
if a > 0:
draw_glow.point((x, y), fill=(r, g, b, a))
img_glow.save('bg_glows.png')
# 3. Button Background (since linear-gradients are not in CSS2)
# Button linear-gradient(135deg, #e0a05b, #f1ba77)
# Let's just make a small 10x100 vertical gradient for button that can be repeated horizontally
img_btn = Image.new('RGB', (1, 100))
draw_btn = ImageDraw.Draw(img_btn)
c1 = hex_to_rgb('#e0a05b')
c2 = hex_to_rgb('#f1ba77')
for y in range(100):
r = int(c1[0] + (c2[0] - c1[0]) * (y / 100))
g = int(c1[1] + (c2[1] - c1[1]) * (y / 100))
b = int(c1[2] + (c2[2] - c1[2]) * (y / 100))
draw_btn.point((0, y), fill=(r, g, b))
img_btn.save('btn_bg.png')