ehsan-dashboards/dashboards/VPN_chanel/test_perfect_gemini.py

258 lines
12 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import math
from PIL import Image, ImageDraw, ImageFont, ImageFilter
import arabic_reshaper
from bidi.algorithm import get_display
FONT_BOLD = '/workspace/personal/dashboards/VPN_chanel/backend/app/static/fonts/Vazirmatn-Bold.ttf'
FONT_REGULAR = '/workspace/personal/dashboards/VPN_chanel/backend/app/static/fonts/Vazirmatn-Regular.ttf'
def get_font(path, size):
try:
return ImageFont.truetype(path, size)
except:
return ImageFont.load_default()
def farsi(text: str) -> str:
return get_display(arabic_reshaper.reshape(text))
# --- VECTOR ICONS ---
def draw_gemini_sparkle(draw, center, size, color):
cx, cy = center
r_outer = size // 2
r_inner = size // 5
points = []
for i in range(8):
angle = i * math.pi / 4
r = r_outer if i % 2 == 0 else r_inner
x = cx + r * math.cos(angle)
y = cy + r * math.sin(angle)
points.append((x, y))
draw.polygon(points, fill=color)
def draw_vector_lock(draw, center, size, color):
cx, cy = center
body_w = int(size * 0.75)
body_h = int(size * 0.55)
bx1 = cx - body_w // 2
by1 = cy - body_h // 6
bx2 = cx + body_w // 2
by2 = by1 + body_h
draw.rounded_rectangle([bx1, by1, bx2, by2], radius=6, fill=color)
shackle_r = int(size * 0.28)
draw.arc([cx - shackle_r, by1 - shackle_r * 2 + 4, cx + shackle_r, by1 + 4], start=180, end=0, fill=color, width=4)
draw.ellipse([cx - 3, by1 + body_h // 3, cx + 3, by1 + body_h // 3 + 6], fill=(15, 23, 42, 255))
def draw_vector_check(draw, center, size, bg_color, check_color=(255, 255, 255)):
cx, cy = center
r = size // 2
draw.ellipse([cx - r, cy - r, cx + r, cy + r], fill=bg_color)
p1 = (cx - r * 0.45, cy)
p2 = (cx - r * 0.1, cy + r * 0.4)
p3 = (cx + r * 0.45, cy - r * 0.35)
draw.line([p1, p2], fill=check_color, width=3)
draw.line([p2, p3], fill=check_color, width=3)
def draw_vector_cross(draw, center, size, bg_color, cross_color=(255, 255, 255)):
cx, cy = center
r = size // 2
draw.ellipse([cx - r, cy - r, cx + r, cy + r], fill=bg_color)
d = r * 0.35
draw.line([(cx - d, cy - d), (cx + d, cy + d)], fill=cross_color, width=3)
draw.line([(cx - d, cy + d), (cx + d, cy - d)], fill=cross_color, width=3)
def create_radial_glow(width, height, center_x, center_y, radius, color):
glow = Image.new('RGBA', (width, height), (0, 0, 0, 0))
draw = ImageDraw.Draw(glow)
r, g, b, max_a = color
steps = 35
for i in range(steps, 0, -1):
cur_r = radius * (i / steps)
alpha = int(max_a * (1 - (i / steps)) ** 1.6)
draw.ellipse([center_x - cur_r, center_y - cur_r, center_x + cur_r, center_y + cur_r], fill=(r, g, b, alpha))
return glow.filter(ImageFilter.GaussianBlur(radius // 5))
def draw_rounded_glass_card(img, bbox, bg_color, border_color, radius=28, shadow=True):
x1, y1, x2, y2 = bbox
if shadow:
shadow_layer = Image.new('RGBA', img.size, (0, 0, 0, 0))
sdraw = ImageDraw.Draw(shadow_layer)
sdraw.rounded_rectangle([x1 + 4, y1 + 10, x2 - 4, y2 + 18], radius=radius, fill=(0, 0, 0, 130))
shadow_layer = shadow_layer.filter(ImageFilter.GaussianBlur(16))
img.alpha_composite(shadow_layer)
card_layer = Image.new('RGBA', img.size, (0, 0, 0, 0))
cdraw = ImageDraw.Draw(card_layer)
cdraw.rounded_rectangle([x1, y1, x2, y2], radius=radius, fill=bg_color, outline=border_color, width=2)
cdraw.line([(x1 + radius, y1 + 1), (x2 - radius, y1 + 1)], fill=(255, 255, 255, 60), width=2)
img.alpha_composite(card_layer)
def draw_pill_button(img, bbox, fill_grad_start, fill_grad_end, text, subtext=None, text_color='#000000'):
x1, y1, x2, y2 = bbox
shadow_layer = Image.new('RGBA', img.size, (0, 0, 0, 0))
sdraw = ImageDraw.Draw(shadow_layer)
sdraw.rounded_rectangle([x1 + 6, y1 + 8, x2 - 6, y2 + 18], radius=(y2 - y1)//2, fill=(0, 0, 0, 150))
sdraw.rounded_rectangle([x1 + 15, y1 + 12, x2 - 15, y2 + 24], radius=(y2 - y1)//2, fill=(fill_grad_start[0], fill_grad_start[1], fill_grad_start[2], 80))
shadow_layer = shadow_layer.filter(ImageFilter.GaussianBlur(14))
img.alpha_composite(shadow_layer)
btn = Image.new('RGBA', (x2 - x1, y2 - y1), (0, 0, 0, 0))
bdraw = ImageDraw.Draw(btn)
for y in range(y2 - y1):
ratio = y / (y2 - y1)
r = int(fill_grad_start[0] * (1 - ratio) + fill_grad_end[0] * ratio)
g = int(fill_grad_start[1] * (1 - ratio) + fill_grad_end[1] * ratio)
b = int(fill_grad_start[2] * (1 - ratio) + fill_grad_end[2] * ratio)
bdraw.line([(0, y), (x2 - x1, y)], fill=(r, g, b, 255))
mask = Image.new('L', (x2 - x1, y2 - y1), 0)
mdraw = ImageDraw.Draw(mask)
mdraw.rounded_rectangle([0, 0, x2 - x1, y2 - y1], radius=(y2 - y1)//2, fill=255)
img.paste(btn, (x1, y1), mask)
odraw = ImageDraw.Draw(img)
odraw.rounded_rectangle([x1, y1, x2, y2], radius=(y2 - y1)//2, outline=(255, 255, 255, 180), width=2)
f_btn = get_font(FONT_BOLD, 36)
odraw.text(((x1 + x2)//2, (y1 + y2)//2 - (10 if subtext else 0)), farsi(text), font=f_btn, fill=text_color, anchor='mm')
if subtext:
f_sub = get_font(FONT_REGULAR, 20)
odraw.text(((x1 + x2)//2, (y1 + y2)//2 + 22), farsi(subtext), font=f_sub, fill='#1F2937', anchor='mm')
def render_gemini_banner_perfected(price_text="۶۰۰,۰۰۰ تومان", original_price="۱,۵۰۰,۰۰۰ تومان"):
W, H = 1080, 1080
base = Image.new('RGBA', (W, H), (10, 14, 26, 255))
glow1 = create_radial_glow(W, H, 780, 470, 480, (147, 51, 234, 85))
glow2 = create_radial_glow(W, H, 300, 470, 360, (59, 130, 246, 40))
glow3 = create_radial_glow(W, H, 540, 910, 400, (245, 158, 11, 55))
base.alpha_composite(glow1)
base.alpha_composite(glow2)
base.alpha_composite(glow3)
draw = ImageDraw.Draw(base)
# Top Category Pill
badge_w, badge_h = 440, 46
bx1, by1 = (W - badge_w)//2, 45
draw_rounded_glass_card(base, [bx1, by1, bx1 + badge_w, by1 + badge_h], (30, 41, 59, 180), (71, 85, 105, 160), radius=23, shadow=False)
draw_gemini_sparkle(draw, (bx1 + 35, by1 + 23), 22, (245, 158, 11))
f_badge = get_font(FONT_BOLD, 21)
draw.text((W // 2 + 10, by1 + 23), farsi("پیشنهاد ویژه اشتراک رسمی هوش مصنوعی"), font=f_badge, fill='#38BDF8', anchor='mm')
# Main Headline
f_title = get_font(FONT_BOLD, 52)
f_sub = get_font(FONT_REGULAR, 24)
draw.text((W // 2, 132), farsi("جهش چشمگیر در سرعت و کیفیت پروژه‌ها"), font=f_title, fill='#FFFFFF', anchor='mm')
draw.text((W // 2, 186), farsi("مقایسه نسخه رایگان با اشتراک اختصاصی ۱۸ ماهه Google Gemini Pro"), font=f_sub, fill='#94A3B8', anchor='mm')
# Card dimensions
card_w = 465
card_h = 590
card_top = 230
# --- LEFT CARD: FREE ---
lx1 = 55
lx2 = lx1 + card_w
ly1 = card_top
ly2 = ly1 + card_h
draw_rounded_glass_card(base, [lx1, ly1, lx2, ly2], (15, 23, 42, 220), (51, 65, 85, 180), radius=30)
draw.rounded_rectangle([lx1 + 30, ly1 + 28, lx1 + 90, ly1 + 88], radius=18, fill=(30, 41, 59, 255), outline=(71, 85, 105, 180), width=1)
draw_vector_lock(draw, (lx1 + 60, ly1 + 58), 34, (148, 163, 184))
f_card_title = get_font(FONT_BOLD, 30)
f_tier = get_font(FONT_BOLD, 20)
f_item = get_font(FONT_REGULAR, 21)
draw.text((lx2 - 35, ly1 + 45), farsi("نسخه معمولی"), font=f_card_title, fill='#E2E8F0', anchor='rm')
draw.text((lx2 - 35, ly1 + 76), farsi("امکانات محدود و پایه"), font=f_tier, fill='#64748B', anchor='rm')
draw.line([(lx1 + 30, ly1 + 110), (lx2 - 30, ly1 + 110)], fill=(51, 65, 85, 180), width=1)
free_items = [
"محدودیت تعداد پرسش در هر ساعت",
"عدم دسترسی به هوش مصنوعی 1.5 Pro",
"بدون فضای ابری ۲ ترابایتی گوگل",
"پایداری ضعیف در زمان اوج ترافیک",
"پاسخ‌های کوتاه با عمق تحلیلی کم",
"عدم اتصال به Docs و Google Drive",
]
cur_y = ly1 + 155
for item in free_items:
draw_vector_cross(draw, (lx2 - 25, cur_y), 24, (239, 68, 68), (255, 255, 255))
draw.text((lx2 - 50, cur_y), farsi(item), font=f_item, fill='#94A3B8', anchor='rm')
cur_y += 58
# Left bottom footer badge: Perfectly balanced
draw.rounded_rectangle([lx1 + 35, ly2 - 75, lx2 - 35, ly2 - 25], radius=15, fill=(30, 41, 59, 230), outline=(51, 65, 85, 200), width=1)
draw.text(((lx1 + lx2)//2, ly2 - 50), farsi("پلن پایه: رایگان"), font=get_font(FONT_BOLD, 21), fill='#94A3B8', anchor='mm')
# --- RIGHT CARD: GEMINI PRO (PREMIUM) ---
rx1 = W - 55 - card_w
rx2 = rx1 + card_w
ry1 = card_top
ry2 = ry1 + card_h
draw_rounded_glass_card(base, [rx1, ry1, rx2, ry2], (24, 18, 45, 240), (168, 85, 247, 230), radius=30)
draw.line([(rx1 + 30, ry1 + 2), (rx2 - 30, ry1 + 2)], fill=(245, 158, 11, 255), width=3)
draw.rounded_rectangle([rx1 + 30, ry1 + 28, rx1 + 90, ry1 + 88], radius=18, fill=(88, 28, 135, 255), outline=(216, 180, 254, 200), width=1)
draw_gemini_sparkle(draw, (rx1 + 60, ry1 + 58), 40, (245, 158, 11))
draw.text((rx2 - 35, ry1 + 45), farsi("Google Gemini Pro"), font=f_card_title, fill='#FFFFFF', anchor='rm')
draw.text((rx2 - 35, ry1 + 76), farsi("اشتراک رسمی و قانونی ۱۸ ماهه"), font=f_tier, fill='#F59E0B', anchor='rm')
draw.line([(rx1 + 30, ry1 + 110), (rx2 - 30, ry1 + 110)], fill=(107, 33, 168, 200), width=1)
pro_items = [
"دسترسی ۱۸ ماهه نامحدود و رسمی",
"پیشرفته‌ترین مدل استدلال 1.5 Pro",
"۲ ترابایت فضای ابری Google One",
"فعال‌سازی ایمن و قانونی روی جیمیل شما",
"پایداری ۱۰۰٪ بدون قطعی در تمام ساعات",
"یکپارچگی مستقیم با Docs و Drive",
]
cur_y = ry1 + 155
for item in pro_items:
draw_vector_check(draw, (rx2 - 25, cur_y), 24, (16, 185, 129), (255, 255, 255))
draw.text((rx2 - 50, cur_y), farsi(item), font=f_item, fill='#F8FAFC', anchor='rm')
cur_y += 58
# Right bottom footer: Balanced with left card, showing Special Price & Strikethrough
draw.rounded_rectangle([rx1 + 35, ly2 - 75, rx2 - 35, ly2 - 25], radius=15, fill=(76, 29, 149, 230), outline=(216, 180, 254, 200), width=1)
# Strikethrough text
f_orig = get_font(FONT_REGULAR, 17)
f_cur = get_font(FONT_BOLD, 22)
orig_str = farsi(original_price)
cur_str = farsi(f"قیمت تخفیفی: {price_text}")
draw.text((rx2 - 60, ly2 - 50), cur_str, font=f_cur, fill='#FCD34D', anchor='rm')
draw.text((rx1 + 60, ly2 - 50), orig_str, font=f_orig, fill='#94A3B8', anchor='lm')
# Strike through center of original price
ow = draw.textlength(orig_str, font=f_orig)
draw.line([(rx1 + 60, ly2 - 50), (rx1 + 60 + ow, ly2 - 50)], fill=(239, 68, 68, 255), width=2)
# --- BOTTOM CTA BUTTON ---
btn_w = 660
btn_h = 100
bx1 = (W - btn_w)//2
by1 = 855
bx2 = bx1 + btn_w
by2 = by1 + btn_h
draw_pill_button(base, [bx1, by1, bx2, by2],
fill_grad_start=(245, 158, 11),
fill_grad_end=(251, 191, 36),
text="سفارش و تحویل فوری اشتراک ۱۸ ماهه",
subtext=f"تخفیف ویژه ۶۰ درصدی • فقط {price_text} • تحویل فوری",
text_color='#0B0F19')
# FOOTER CONTACT
f_footer = get_font(FONT_BOLD, 22)
draw.text((W // 2, 995), farsi("سفارش و مشاوره فوری: NetVibe_admin@ • کانال رسمی: NetVibe_VPN@"), font=f_footer, fill='#94A3B8', anchor='mm')
final_img = Image.new('RGB', (W, H), (10, 14, 26))
final_img.paste(base, (0, 0), base)
return final_img
im_perfect = render_gemini_banner_perfected("۶۰۰,۰۰۰ تومان", "۱,۵۰۰,۰۰۰ تومان")
im_perfect.save('/tmp/perfect_gemini_banner.png', quality=95)
print("Saved /tmp/perfect_gemini_banner.png successfully!")