- 新增 PosterSmartEngine,AI 生成文案 + 海报渲染 - 5 种布局支持文本换行和自适应字体 - 修复按钮/标签颜色显示问题 - 优化渐变遮罩和内容区域计算 - Prompt 优化:标题格式为产品名+描述
73 lines
2.3 KiB
Python
73 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
海报内容数据模型
|
|
"""
|
|
|
|
from dataclasses import dataclass, field
|
|
from typing import List, Optional
|
|
from PIL import Image
|
|
|
|
|
|
@dataclass
|
|
class PosterContent:
|
|
"""
|
|
海报内容模型
|
|
|
|
Attributes:
|
|
title: 主标题 (必填)
|
|
subtitle: 副标题
|
|
price: 价格 (如 "¥199")
|
|
price_suffix: 价格后缀 (如 "/人", "/晚")
|
|
tags: 标签列表 (如 ["周末游", "亲子"])
|
|
highlights: 亮点标签 (如 ["环境好", "出片"])
|
|
features: 特色列表 (如 ["海景房", "含早餐"])
|
|
details: 详情列表 (如 ["距地铁5分钟", "可带宠物"])
|
|
label: 角标/徽章 (如 "精选推荐")
|
|
emoji: emoji符号 (如 "🍰")
|
|
image: 背景图片 (PIL Image对象)
|
|
"""
|
|
title: str
|
|
subtitle: str = ""
|
|
price: str = ""
|
|
price_suffix: str = ""
|
|
tags: List[str] = field(default_factory=list)
|
|
highlights: List[str] = field(default_factory=list)
|
|
features: List[str] = field(default_factory=list)
|
|
details: List[str] = field(default_factory=list)
|
|
label: str = ""
|
|
emoji: str = ""
|
|
image: Optional[Image.Image] = None
|
|
|
|
@classmethod
|
|
def from_dict(cls, data: dict) -> 'PosterContent':
|
|
"""从字典创建内容对象"""
|
|
return cls(
|
|
title=data.get('title', ''),
|
|
subtitle=data.get('subtitle', ''),
|
|
price=data.get('price', ''),
|
|
price_suffix=data.get('price_suffix', ''),
|
|
tags=data.get('tags', []),
|
|
highlights=data.get('highlights', []),
|
|
features=data.get('features', []),
|
|
details=data.get('details', []),
|
|
label=data.get('label', ''),
|
|
emoji=data.get('emoji', ''),
|
|
image=data.get('image'),
|
|
)
|
|
|
|
def to_dict(self) -> dict:
|
|
"""转换为字典 (不含image)"""
|
|
return {
|
|
'title': self.title,
|
|
'subtitle': self.subtitle,
|
|
'price': self.price,
|
|
'price_suffix': self.price_suffix,
|
|
'tags': self.tags,
|
|
'highlights': self.highlights,
|
|
'features': self.features,
|
|
'details': self.details,
|
|
'label': self.label,
|
|
'emoji': self.emoji,
|
|
}
|