ehsan-dashboards/dashboards/VPN_chanel/backend/app/banner_generator.py

557 lines
26 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 os
import re
import math
import hashlib
import logging
from typing import Optional, Tuple
from PIL import Image, ImageDraw, ImageFont, ImageFilter
import arabic_reshaper
from bidi.algorithm import get_display
logger = logging.getLogger("banner_generator")
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
BANNER_DIR = os.path.join(BASE_DIR, "static", "banners")
FONTS_DIR = os.path.join(BASE_DIR, "static", "fonts")
os.makedirs(BANNER_DIR, exist_ok=True)
os.makedirs(FONTS_DIR, exist_ok=True)
FONT_BOLD = os.path.join(FONTS_DIR, "Vazirmatn-Bold.ttf")
FONT_REGULAR = os.path.join(FONTS_DIR, "Vazirmatn-Regular.ttf")
def persian_text(text: str) -> str:
"""Format and reshape Persian text for correct RTL and letter joining."""
if not text:
return ""
try:
reshaped = arabic_reshaper.reshape(text)
return get_display(reshaped)
except Exception:
return text
def get_font(path: str, size: int):
try:
if os.path.exists(path):
return ImageFont.truetype(path, size)
return ImageFont.load_default()
except Exception:
return ImageFont.load_default()
# --- VECTOR DRAWING HELPERS ---
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 draw_vector_shield(draw, center, size, color):
cx, cy = center
w = int(size * 0.8)
h = size
y1 = cy - h//2
y2 = cy + h//2
pts = [
(cx - w//2, y1),
(cx + w//2, y1),
(cx + w//2, cy + h*0.1),
(cx, y2),
(cx - w//2, cy + h*0.1)
]
draw.polygon(pts, fill=color)
def draw_vector_lightning(draw, center, size, color):
cx, cy = center
s = size // 2
pts = [
(cx + s*0.2, cy - s),
(cx - s*0.6, cy + s*0.05),
(cx - s*0.05, cy + s*0.05),
(cx - s*0.2, cy + s),
(cx + s*0.6, cy - s*0.05),
(cx + s*0.05, cy - s*0.05),
]
draw.polygon(pts, fill=color)
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
# Clean ambient glow
shadow_layer = Image.new('RGBA', img.size, (0, 0, 0, 0))
sdraw = ImageDraw.Draw(shadow_layer)
sdraw.rounded_rectangle([x1 + 10, y1 + 10, x2 - 10, y2 + 20], radius=(y2 - y1)//2, fill=(fill_grad_start[0], fill_grad_start[1], fill_grad_start[2], 90))
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, 34)
odraw.text(((x1 + x2)//2, (y1 + y2)//2 - (10 if subtext else 0)), persian_text(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), persian_text(subtext), font=f_sub, fill='#1F2937', anchor='mm')
# ==============================================================================
# 1. GEMINI PRO MASTER BANNER (1080x1080)
# ==============================================================================
def create_gemini_banner(
headline: str = "جهش چشمگیر در سرعت و کیفیت پروژه‌ها",
price_toman: str = "۶۰۰.۰۰۰ تومان",
is_discount: bool = True,
duration: str = "اشتراک ۱۸ ماهه اختصاصی"
) -> str:
"""
Renders high-end commercial 1080x1080 comparison banner for Google Gemini Pro:
- Side-by-side Free vs. Pro comparison cards
- Sharp vector icons (Sparkles, Padlock, Anti-aliased Checks & Crosses)
- Golden CTA pill with smooth lighting
"""
W, H = 1080, 1080
base = Image.new('RGBA', (W, H), (10, 14, 26, 255))
# Atmospheric glows
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, 60))
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), persian_text("پیشنهاد ویژه اشتراک رسمی هوش مصنوعی"), font=f_badge, fill='#38BDF8', anchor='mm')
# Main Headline
f_title = get_font(FONT_BOLD, 50)
f_sub = get_font(FONT_REGULAR, 23)
draw.text((W // 2, 132), persian_text(headline), font=f_title, fill='#FFFFFF', anchor='mm')
draw.text((W // 2, 186), persian_text("مقایسه نسخه رایگان با اشتراک اختصاصی ۱۸ ماهه 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), persian_text("نسخه معمولی"), font=f_card_title, fill='#E2E8F0', anchor='rm')
draw.text((lx2 - 35, ly1 + 76), persian_text("امکانات محدود و پایه"), 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), persian_text(item), font=f_item, fill='#94A3B8', anchor='rm')
cur_y += 58
# Left bottom footer badge
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), persian_text("پلن پایه: رایگان"), 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), persian_text("Google Gemini Pro"), font=f_card_title, fill='#FFFFFF', anchor='rm')
draw.text((rx2 - 35, ry1 + 76), persian_text("اشتراک رسمی و قانونی ۱۸ ماهه"), 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), persian_text(item), font=f_item, fill='#F8FAFC', anchor='rm')
cur_y += 58
# Right bottom footer: Balanced with left card
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)
f_orig = get_font(FONT_REGULAR, 17)
f_cur = get_font(FONT_BOLD, 22)
orig_str = persian_text("۱.۵۰۰.۰۰۰ تومان")
cur_str = persian_text(f"قیمت تخفیفی: {price_toman}")
draw.text((rx2 - 40, ly2 - 50), cur_str, font=f_cur, fill='#FCD34D', anchor='rm')
draw.text((rx1 + 40, ly2 - 50), orig_str, font=f_orig, fill='#94A3B8', anchor='lm')
# Strike through line at exact vertical center
ow = draw.textlength(orig_str, font=f_orig)
draw.line([(rx1 + 40, ly2 - 50), (rx1 + 40 + 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_toman} • تحویل فوری",
text_color='#0B0F19')
# FOOTER CONTACT
f_footer = get_font(FONT_BOLD, 22)
draw.text((W // 2, 995), persian_text("سفارش و مشاوره فوری: 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)
# Save banner
content_str = f"gemini_{headline}_{price_toman}_{duration}"
img_hash = hashlib.md5(content_str.encode()).hexdigest()[:10]
out_filename = f"gemini_banner_{img_hash}.png"
out_png_path = os.path.join(BANNER_DIR, out_filename)
final_img.save(out_png_path, "PNG", quality=95)
logger.info(f"Generated premium Gemini banner: {out_png_path}")
return f"/static/banners/{out_filename}"
# ==============================================================================
# 2. VPN SERVICE MASTER BANNER (1080x1080)
# ==============================================================================
def create_vpn_banner(
title: str = "اتصال پرسرعت، پایدار و بدون قطعی",
subtitle: str = "مناسب اینستاگرام، تلگرام، ترید، یوتیوب و وب‌گردی با پینگ فوق‌العاده",
topic_badge: str = "⚡ سرویس اینترنت آزاد و پایدار NetVibe",
card1_title: str = "پلن ۲ کاربره نامحدود",
card1_sub: str = "۳۰۰.۰۰۰ تومان • یک‌ماهه",
card2_title: str = "پلن ۳ کاربره نامحدود",
card2_sub: str = "۳۵۰.۰۰۰ تومان • یک‌ماهه",
card3_title: str = "حجم کاملاً نامحدود ♾️",
card3_sub: str = "سوییچ هوشمند • ساب‌لینک",
brand: str = "@NetVibe_VPN"
) -> str:
"""
Renders modern 1080x1080 comparison banner for NetVibe VPN plans:
- Plan 2-User: 300,000 Tomans
- Plan 3-User: 350,000 Tomans (Featured & Best-seller)
- Cyan & Violet cyberpunk aesthetic
"""
W, H = 1080, 1080
base = Image.new('RGBA', (W, H), (11, 15, 28, 255))
glow1 = create_radial_glow(W, H, 300, 480, 450, (6, 182, 212, 65))
glow2 = create_radial_glow(W, H, 780, 480, 450, (139, 92, 246, 75))
glow3 = create_radial_glow(W, H, 540, 910, 380, (16, 185, 129, 50))
base.alpha_composite(glow1)
base.alpha_composite(glow2)
base.alpha_composite(glow3)
draw = ImageDraw.Draw(base)
# Top Category Pill
badge_w, badge_h = 420, 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_vector_shield(draw, (bx1 + 35, by1 + 23), 22, (6, 182, 212))
f_badge = get_font(FONT_BOLD, 21)
draw.text((W // 2 + 10, by1 + 23), persian_text("سرویس اینترنت پرسرعت و پایدار NetVibe"), font=f_badge, fill='#38BDF8', anchor='mm')
# Main Headline
f_title = get_font(FONT_BOLD, 50)
f_sub = get_font(FONT_REGULAR, 23)
draw.text((W // 2, 132), persian_text(title), font=f_title, fill='#FFFFFF', anchor='mm')
draw.text((W // 2, 186), persian_text(subtitle), font=f_sub, fill='#94A3B8', anchor='mm')
# Card dimensions
card_w = 465
card_h = 590
card_top = 230
# --- LEFT CARD: PLAN 2-USER ---
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, 230), (14, 165, 233, 200), radius=30)
draw.rounded_rectangle([lx1 + 30, ly1 + 28, lx1 + 90, ly1 + 88], radius=18, fill=(12, 74, 110, 255), outline=(56, 189, 248, 180), width=1)
draw_vector_shield(draw, (lx1 + 60, ly1 + 58), 34, (56, 189, 248))
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), persian_text(card1_title), font=f_card_title, fill='#FFFFFF', anchor='rm')
draw.text((lx2 - 35, ly1 + 76), persian_text("مناسب استفاده دو دستگاه همزمان"), font=f_tier, fill='#38BDF8', anchor='rm')
draw.line([(lx1 + 30, ly1 + 110), (lx2 - 30, ly1 + 110)], fill=(14, 116, 144, 180), width=1)
plan2_items = [
"حجم کاملاً نامحدود بدون سقف مصرف",
"سازگار با همراه اول، ایرانسل و وای‌فای",
"اتصال آنی و پایدار بدون افت سرعت",
"اتصال فوق‌العاده روان و بدون قطعی در ساعات اوج",
"حفظ کامل حریم خصوصی و امنیت داده‌ها",
"پشتیبانی فعال ۲۴ ساعته تا انتهای اشتراک",
]
cur_y = ly1 + 155
for item in plan2_items:
draw_vector_check(draw, (lx2 - 25, cur_y), 24, (14, 165, 233), (255, 255, 255))
draw.text((lx2 - 50, cur_y), persian_text(item), font=f_item, fill='#E2E8F0', anchor='rm')
cur_y += 58
# Price at bottom of Plan 2
draw.rounded_rectangle([lx1 + 35, ly2 - 75, lx2 - 35, ly2 - 25], radius=15, fill=(12, 74, 110, 230), outline=(56, 189, 248, 180), width=1)
draw.text(((lx1 + lx2)//2, ly2 - 50), persian_text("ماهانه: ۳۰۰.۰۰۰ تومان"), font=get_font(FONT_BOLD, 21), fill='#FFFFFF', anchor='mm')
# --- RIGHT CARD: PLAN 3-USER (FEATURED) ---
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], (26, 19, 52, 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_vector_lightning(draw, (rx1 + 60, ry1 + 58), 34, (245, 158, 11))
draw.text((rx2 - 35, ry1 + 45), persian_text(card2_title), font=f_card_title, fill='#FFFFFF', anchor='rm')
draw.text((rx2 - 35, ry1 + 76), persian_text("⭐ پرفروش‌ترین و اقتصادی‌ترین پلن"), font=f_tier, fill='#F59E0B', anchor='rm')
draw.line([(rx1 + 30, ry1 + 110), (rx2 - 30, ry1 + 110)], fill=(107, 33, 168, 200), width=1)
plan3_items = [
"اتصال ۳ دستگاه همزمان با حجم نامحدود",
"سرورهای اختصاصی با بالاترین پهنای باند",
"بدون قطعی و افت سرعت در اینترنت ملی",
"سازگار با Android, iOS, Windows, Mac",
"آی‌پی ثابت مناسب ترید و بایننس",
"تضمین بازگشت وجه در صورت عدم رضایت",
]
cur_y = ry1 + 155
for item in plan3_items:
draw_vector_check(draw, (rx2 - 25, cur_y), 24, (168, 85, 247), (255, 255, 255))
draw.text((rx2 - 50, cur_y), persian_text(item), font=f_item, fill='#F8FAFC', anchor='rm')
cur_y += 58
# Price at bottom of Plan 3
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)
draw.text(((rx1 + rx2)//2, ly2 - 50), persian_text("ماهانه: ۳۵۰.۰۰۰ تومان"), font=get_font(FONT_BOLD, 21), fill='#FCD34D', anchor='mm')
# --- 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=(16, 185, 129),
fill_grad_end=(52, 211, 153),
text="تحویل آنی و تست اتصال قبل از پرداخت",
subtext="پشتیبانی ۲۴ ساعته و کانفیگ رایگان تمام پلتفرم‌ها",
text_color='#062D1F')
# FOOTER CONTACT
f_footer = get_font(FONT_BOLD, 22)
draw.text((W // 2, 995), persian_text(f"ثبت سفارش و دریافت تست: NetVibe_admin@ • کانال رسمی: {brand}"), font=f_footer, fill='#94A3B8', anchor='mm')
final_img = Image.new('RGB', (W, H), (11, 15, 28))
final_img.paste(base, (0, 0), base)
# Save banner
content_str = f"vpn_{title}_{card1_title}_{card2_title}_{brand}"
img_hash = hashlib.md5(content_str.encode()).hexdigest()[:10]
out_filename = f"vpn_banner_{img_hash}.png"
out_png_path = os.path.join(BANNER_DIR, out_filename)
final_img.save(out_png_path, "PNG", quality=95)
logger.info(f"Generated premium VPN banner: {out_png_path}")
return f"/static/banners/{out_filename}"
# ==============================================================================
# 3. BANNER POOL SELECTION HELPERS (Custom Pool with Fallback)
# ==============================================================================
import random
POOL_DIR = os.path.join(BASE_DIR, "static", "banner_pool")
GEMINI_POOL_DIR = os.path.join(POOL_DIR, "gemini")
VPN_POOL_DIR = os.path.join(POOL_DIR, "vpn")
def get_gemini_banner_from_pool_or_generate(
headline: str = "جهش چشمگیر در سرعت و کیفیت پروژه‌ها",
price_toman: str = "۶۰۰.۰۰۰ تومان",
is_discount: bool = True,
banner_type: str = "discount_600k" # 'discount_600k', 'multi_tier_6gmail', or 'any'
) -> str:
"""
STRICTLY selects from the user's uploaded Gemini banners.
Does NOT generate procedural banners for Gemini.
- 'discount_600k': selects between Gemini_Pro_600k_Discount_Laptop.png and Gemini_Pro_600k_Discount_Robot.png
- 'multi_tier_6gmail': selects Gemini_Pro_Multi_Tier_6Gmail.png
"""
valid_extensions = ('.png', '.jpg', '.jpeg', '.webp')
if os.path.exists(GEMINI_POOL_DIR):
pool_files = [f for f in os.listdir(GEMINI_POOL_DIR) if f.lower().endswith(valid_extensions)]
if pool_files:
filtered = []
if banner_type == "discount_999k":
filtered = [f for f in pool_files if "999k" in f.lower()]
elif banner_type == "discount_1200k":
filtered = [f for f in pool_files if "1200k" in f.lower()]
elif banner_type == "multi_tier_6gmail":
filtered = [f for f in pool_files if "6gmail" in f.lower() and "1200k" not in f.lower() and "999k" not in f.lower()]
elif banner_type == "discount_600k":
filtered = [f for f in pool_files if ("600k" in f.lower() or "discount" in f.lower()) and "1200k" not in f.lower() and "999k" not in f.lower() and "multi" not in f.lower()]
chosen_list = filtered if filtered else pool_files
chosen = random.choice(chosen_list)
logger.info(f"Strictly using user-provided Gemini banner: {chosen} (type: {banner_type})")
return f"/static/banner_pool/gemini/{chosen}"
# Static hardcoded fallback to user images if dir scan has any issue
if banner_type == "discount_999k":
return "/static/banner_pool/gemini/Gemini_Pro_999k_Discount_Holo_Pedestal_6Gmail.png"
if banner_type == "discount_1200k":
return random.choice([
"/static/banner_pool/gemini/Gemini_Pro_1200k_Discount_Robot_6Gmail.png",
"/static/banner_pool/gemini/Gemini_Pro_1200k_Discount_Gold_Pedestal_6Gmail.png"
])
if banner_type == "multi_tier_6gmail":
return "/static/banner_pool/gemini/Gemini_Pro_Multi_Tier_6Gmail.png"
return random.choice([
"/static/banner_pool/gemini/Gemini_Pro_600k_Discount_Laptop.png",
"/static/banner_pool/gemini/Gemini_Pro_600k_Discount_Robot.png"
])
def get_vpn_banner_from_pool_or_generate(
title: str = "اتصال پرسرعت، پایدار و بدون قطعی",
card1_title: str = "پلن ۲ کاربره نامحدود",
card2_title: str = "پلن ۳ کاربره نامحدود",
brand: str = "@NetVibe_VPN"
) -> str:
"""
Selects a banner from the user-uploaded VPN Banner Pool, or dynamically generates one.
"""
if os.path.exists(VPN_POOL_DIR):
valid_extensions = ('.png', '.jpg', '.jpeg', '.webp')
pool_files = [f for f in os.listdir(VPN_POOL_DIR) if f.lower().endswith(valid_extensions)]
if pool_files:
chosen = random.choice(pool_files)
logger.info(f"Selected VPN banner from pool: {chosen} (pool size: {len(pool_files)})")
return f"/static/banner_pool/vpn/{chosen}"
return create_vpn_banner(title=title, card1_title=card1_title, card2_title=card2_title, brand=brand)