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)) def create_radial_glow(width, height, center_x, center_y, radius, color): # color: (r, g, b, alpha) glow = Image.new('RGBA', (width, height), (0, 0, 0, 0)) draw = ImageDraw.Draw(glow) r, g, b, max_a = color steps = 40 for i in range(steps, 0, -1): cur_r = radius * (i / steps) alpha = int(max_a * (1 - (i / steps)) ** 1.8) 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 // 6)) def draw_rounded_glass_card(img, bbox, bg_color, border_color, radius=28, shadow=True): # shadow x1, y1, x2, y2 = bbox w, h = x2 - x1, y2 - y1 if shadow: shadow_layer = Image.new('RGBA', img.size, (0, 0, 0, 0)) sdraw = ImageDraw.Draw(shadow_layer) sdraw.rounded_rectangle([x1 + 4, y1 + 12, x2 - 4, y2 + 18], radius=radius, fill=(0, 0, 0, 110)) 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) # subtle top light highlight cdraw.line([(x1 + radius, y1 + 1), (x2 - radius, y1 + 1)], fill=(255, 255, 255, 70), 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 shadow_layer = Image.new('RGBA', img.size, (0, 0, 0, 0)) sdraw = ImageDraw.Draw(shadow_layer) sdraw.rounded_rectangle([x1, y1 + 8, x2, y2 + 16], radius=(y2 - y1)//2, fill=(0, 0, 0, 140)) sdraw.rounded_rectangle([x1 + 10, y1 + 14, x2 - 10, y2 + 22], radius=(y2 - y1)//2, fill=(245, 158, 11, 70)) shadow_layer = shadow_layer.filter(ImageFilter.GaussianBlur(14)) img.alpha_composite(shadow_layer) # button gradient 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 rounded 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) # composite button img.paste(btn, (x1, y1), mask) # outline glow odraw = ImageDraw.Draw(img) odraw.rounded_rectangle([x1, y1, x2, y2], radius=(y2 - y1)//2, outline=(255, 255, 255, 160), width=2) # text f_btn = get_font(FONT_BOLD, 38) odraw.text(((x1 + x2)//2, (y1 + y2)//2 - (8 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 + 24), farsi(subtext), font=f_sub, fill='#1F2937', anchor='mm') def render_gemini_master_banner(price_text="۶۰۰,۰۰۰ تومان", original_price="۱,۵۰۰,۰۰۰ تومان"): W, H = 1080, 1080 base = Image.new('RGBA', (W, H), (11, 15, 25, 255)) # Background soft radial lights glow1 = create_radial_glow(W, H, 780, 480, 450, (147, 51, 234, 75)) # purple glow for Pro glow2 = create_radial_glow(W, H, 300, 480, 350, (59, 130, 246, 35)) # subtle blue glow glow3 = create_radial_glow(W, H, 540, 920, 380, (245, 158, 11, 45)) # golden glow for CTA base.alpha_composite(glow1) base.alpha_composite(glow2) base.alpha_composite(glow3) draw = ImageDraw.Draw(base) # TOP HEADER BADGE badge_w, badge_h = 420, 48 bx1, by1 = (W - badge_w)//2, 50 draw_rounded_glass_card(base, [bx1, by1, bx1 + badge_w, by1 + badge_h], (30, 41, 59, 180), (71, 85, 105, 150), radius=24, shadow=False) f_badge = get_font(FONT_BOLD, 22) draw.text((W // 2, by1 + 24), farsi("⚡ پیشنهاد ویژه اشتراک هوش مصنوعی"), font=f_badge, fill='#38BDF8', anchor='mm') # MAIN TITLE f_title = get_font(FONT_BOLD, 54) f_sub = get_font(FONT_REGULAR, 26) draw.text((W // 2, 140), farsi("ارتقای لول کارها و پروژه‌ها"), font=f_title, fill='#FFFFFF', anchor='mm') draw.text((W // 2, 195), farsi("مقایسه نسخه رایگان با نسخه اختصاصی ۱۸ ماهه Google Gemini Pro"), font=f_sub, fill='#94A3B8', anchor='mm') # TWO COLUMNS card_w = 460 card_h = 580 card_top = 245 # --- LEFT CARD: FREE / BASIC --- lx1 = 60 lx2 = lx1 + card_w ly1 = card_top ly2 = ly1 + card_h draw_rounded_glass_card(base, [lx1, ly1, lx2, ly2], (15, 23, 42, 210), (51, 65, 85, 180), radius=32) # Left Header f_card_title = get_font(FONT_BOLD, 32) f_tier = get_font(FONT_BOLD, 22) f_item = get_font(FONT_REGULAR, 22) # Lock Icon Badge draw.rounded_rectangle([lx1 + 35, ly1 + 35, lx1 + 95, ly1 + 95], radius=18, fill=(30, 41, 59, 255), outline=(71, 85, 105, 200), width=1) draw.text((lx1 + 65, ly1 + 65), "🔒", font=get_font(FONT_BOLD, 26), fill='#94A3B8', anchor='mm') draw.text((lx2 - 40, ly1 + 52), farsi("نسخه رایگان"), font=f_card_title, fill='#E2E8F0', anchor='rm') draw.text((lx2 - 40, ly1 + 86), farsi("محدود و اشتراکی"), font=f_tier, fill='#64748B', anchor='rm') draw.line([(lx1 + 35, ly1 + 125), (lx2 - 35, ly1 + 125)], fill=(51, 65, 85, 180), width=1) # Free items free_items = [ ("❌", "محدودیت تعداد پیام در ساعت"), ("❌", "عدم دسترسی به مدل‌های عمیق Pro"), ("❌", "بدون فضای ابری ۲ ترابایتی گوگل"), ("❌", "عدم اتصال به ابزارهای برنامه‌نویسی پیشرفته"), ("❌", "پایداری پایین در زمان اوج ترافیک"), ("❌", "سرعت پاسخگویی استاندارد و پایین"), ] cur_y = ly1 + 165 for icon, item in free_items: draw.text((lx2 - 40, cur_y), farsi(item), font=f_item, fill='#94A3B8', anchor='rm') draw.text((lx2 - 15, cur_y), icon, font=get_font(FONT_BOLD, 18), fill='#EF4444', anchor='mm') cur_y += 58 # Free Price tag at bottom of left card draw.rounded_rectangle([lx1 + 40, ly2 - 80, lx2 - 40, ly2 - 30], radius=16, fill=(30, 41, 59, 180)) draw.text(((lx1 + lx2)//2, ly2 - 55), farsi("بدون هزینه • کاربرد مقدماتی"), font=get_font(FONT_BOLD, 20), fill='#64748B', anchor='mm') # --- RIGHT CARD: GEMINI PRO (PREMIUM) --- rx1 = W - 60 - card_w rx2 = rx1 + card_w ry1 = card_top ry2 = ry1 + card_h # Glowing border card draw_rounded_glass_card(base, [rx1, ry1, rx2, ry2], (24, 18, 43, 230), (168, 85, 247, 240), radius=32) # Extra golden accent on top border draw.line([(rx1 + 35, ry1 + 2), (rx2 - 35, ry1 + 2)], fill=(245, 158, 11, 230), width=3) # Sparkle / Brain Icon Badge draw.rounded_rectangle([rx1 + 35, ry1 + 35, rx1 + 95, ry1 + 95], radius=18, fill=(88, 28, 135, 255), outline=(216, 180, 254, 220), width=1) draw.text((rx1 + 65, ry1 + 65), "💎", font=get_font(FONT_BOLD, 26), fill='#F59E0B', anchor='mm') draw.text((rx2 - 40, ry1 + 52), farsi("Google Gemini Pro"), font=f_card_title, fill='#FFFFFF', anchor='rm') draw.text((rx2 - 40, ry1 + 86), farsi("اشتراک اختصاصی ۱۸ ماهه"), font=f_tier, fill='#F59E0B', anchor='rm') draw.line([(rx1 + 35, ry1 + 125), (rx2 - 35, ry1 + 125)], fill=(107, 33, 168, 200), width=1) # Pro items pro_items = [ ("⭐", "دسترسی ۱۸ ماهه نامحدود بدون قطعی"), ("⚡", "قدرتمندترین مدل استدلال و کدنویسی 1.5 Pro"), ("☁️", "۲ ترابایت فضای ابری اختصاصی Google One"), ("🛡️", "فعال‌سازی قانونی روی جیمیل شخصی شما"), ("🚀", "پردازش اسناد حجیم و ویدیوهای طولانی"), ("🔄", "یکپارچگی کامل با Docs, Drive و Gmail"), ] cur_y = ry1 + 165 for icon, item in pro_items: draw.text((rx2 - 40, cur_y), farsi(item), font=f_item, fill='#F1F5F9', anchor='rm') draw.text((rx2 - 15, cur_y), icon, font=get_font(FONT_BOLD, 18), fill='#F59E0B', anchor='mm') cur_y += 58 # Old price strikethrough draw.text(((rx1 + rx2)//2, ly2 - 55), farsi(f"قیمت پایه: {original_price}"), font=get_font(FONT_REGULAR, 20), fill='#A855F7', anchor='mm') # strikethrough line tw = draw.textlength(farsi(f"قیمت پایه: {original_price}"), font=get_font(FONT_REGULAR, 20)) tx = (rx1 + rx2)//2 draw.line([(tx - tw//2, ly2 - 55), (tx + tw//2, ly2 - 55)], fill=(239, 68, 68, 220), width=2) # --- BOTTOM CTA BUTTON --- btn_w = 640 btn_h = 105 bx1 = (W - btn_w)//2 by1 = 860 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=f"تخفیف ویژه: {price_text}", subtext="ظرفیت محدود • تحویل و فعال‌سازی فوری روی جیمیل شما", text_color='#0B0F19') # FOOTER ADMIN CONTACT f_footer = get_font(FONT_BOLD, 22) draw.text((W // 2, 1010), farsi("مشاوره و فعال‌سازی آنی: NetVibe_admin@ • کانال رسمی: NetVibe_VPN@"), font=f_footer, fill='#94A3B8', anchor='mm') # Convert to RGB and return final_img = Image.new('RGB', (W, H), (11, 15, 25)) final_img.paste(base, (0, 0), base) return final_img # Test saving im = render_gemini_master_banner("۶۰۰,۰۰۰ تومان", "۱,۵۰۰,۰۰۰ تومان") im.save('/tmp/new_gemini_masterpiece.png', quality=95) print("Saved /tmp/new_gemini_masterpiece.png successfully!")