#!/usr/bin/env python3 """Создание седьмой карточки — «Июль — середина года».""" import os from PIL import Image, ImageDraw, ImageFont, ImageFilter PHOTO_PATH = "/var/lib/lifeos/hermes/.hermes/cache/images/img_f654f52cfc02.jpg" OUT_DIR = "/var/lib/lifeos/hermes/previews/svetlana-cards" W, H = 1080, 1920 BG_COLOR = (245, 240, 232) TEXT_COLOR = (80, 50, 35) ACCENT_COLOR = (140, 110, 80) LIGHT_COLOR = (160, 140, 120) font_title = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf", 52) font_body = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf", 40) font_small = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf", 32) font_tiny = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf", 28) font_italic = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf", 30) def draw_centered(draw, text, font, color, cx, y): bbox = draw.textbbox((0, 0), text, font=font) tw = bbox[2] - bbox[0] x = cx - tw // 2 draw.text((x, y), text, font=font, fill=color) card = Image.new("RGB", (W, H), BG_COLOR) draw = ImageDraw.Draw(card) # Загружаем и обрезаем фото photo = Image.open(PHOTO_PATH).convert("RGB") pw, ph = photo.size crop_h = int(ph * 0.56) photo = photo.crop((0, 0, pw, crop_h)) # Размер фото: 55% высоты photo_h = int(H * 0.55) photo_w = int(photo_h * photo.width / photo.height) if photo_w > W: photo_w = W photo_h = int(photo_w * photo.height / photo.width) photo = photo.resize((photo_w, photo_h), Image.LANCZOS) # Мягкая виньетка overlay = Image.new("RGBA", (photo_w, photo_h), (0, 0, 0, 0)) for y in range(int(photo_h * 0.55), photo_h): alpha = int((y - photo_h * 0.55) / (photo_h * 0.45) * 100) for x in range(photo_w): overlay.putpixel((x, y), (0, 0, 0, min(alpha, 90))) photo_rgba = photo.convert("RGBA") photo_rgba = Image.alpha_composite(photo_rgba, overlay) photo = photo_rgba.convert("RGB") x_off = (W - photo_w) // 2 card.paste(photo, (x_off, 0)) # Текст на фото: «Июль — середина года.» draw_centered(draw, "Июль — середина года.", font_title, (255, 245, 235), W // 2, 40) # Текст под фото lines = [ ("", font_body, TEXT_COLOR), ("Если чувствуете себя выжатой", font_body, TEXT_COLOR), ("при внешнем «всё ок» —", font_body, TEXT_COLOR), ("это не значит, что надо больше отдыхать.", font_body, TEXT_COLOR), ("", font_body, TEXT_COLOR), ("Это значит — пора вернуть себе СЕБЯ.", font_title, ACCENT_COLOR), ("", font_body, TEXT_COLOR), ("", font_body, TEXT_COLOR), ("Обнимаю. Ваша Светлана", font_small, LIGHT_COLOR), ] y = photo_h + 50 for text, font, color in lines: if text: draw_centered(draw, text, font, color, W // 2, y) if font == font_title: y += 70 elif font == font_small: y += 50 else: y += 50 else: y += 20 # Декоративная линия перед подписью draw.line([(W//2 - 60, y - 10), (W//2 + 60, y - 10)], fill=(180, 160, 140), width=1) path = os.path.join(OUT_DIR, "07_iyul.png") card.save(path, "PNG", quality=95) print(f"✅ {path}") print(f" Размер: {os.path.getsize(path)//1024} KB")