'commit'
This commit is contained in:
@@ -75,8 +75,9 @@ async def refine_prompt(req: RefineRequest):
|
|||||||
1. 描述画面主体、背景、光影、色彩、构图。
|
1. 描述画面主体、背景、光影、色彩、构图。
|
||||||
2. 风格要求:现代感、科技感、精美、3D渲染风格或高品质插画风格。
|
2. 风格要求:现代感、科技感、精美、3D渲染风格或高品质插画风格。
|
||||||
3. 融入新能源、绿色环保、充电桩等元素。
|
3. 融入新能源、绿色环保、充电桩等元素。
|
||||||
4. 直接输出提示词内容,不要包含“好的”、“以下是”等无关废话。
|
4. 关于品牌元素:画面中可自然融入品牌Logo的视觉元素(如配色、形状),能用多少就用多少,有元素体现即可,不必生搬硬套,保持画面自然和谐。
|
||||||
5. 字数在100-300字之间。
|
5. 直接输出提示词内容,不要包含“好的”、“以下是”等无关废话。
|
||||||
|
6. 字数在100-300字之间。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
refined_prompt = ""
|
refined_prompt = ""
|
||||||
@@ -116,8 +117,9 @@ async def generate_poster(req: GenerateRequest):
|
|||||||
1. 描述画面主体、背景、光影、色彩、构图。
|
1. 描述画面主体、背景、光影、色彩、构图。
|
||||||
2. 风格要求:现代感、科技感、精美、3D渲染风格或高品质插画风格。
|
2. 风格要求:现代感、科技感、精美、3D渲染风格或高品质插画风格。
|
||||||
3. 融入新能源、绿色环保、充电桩等元素。
|
3. 融入新能源、绿色环保、充电桩等元素。
|
||||||
4. 直接输出提示词内容,不要包含“好的”、“以下是”等无关废话。
|
4. 关于品牌元素:画面中可自然融入品牌Logo的视觉元素(如配色、形状),能用多少就用多少,有元素体现即可,不必生搬硬套,保持画面自然和谐。
|
||||||
5. 字数在100-300字之间。
|
5. 直接输出提示词内容,不要包含“好的”、“以下是”等无关废话。
|
||||||
|
6. 字数在100-300字之间。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
refined_prompt = ""
|
refined_prompt = ""
|
||||||
@@ -133,7 +135,9 @@ async def generate_poster(req: GenerateRequest):
|
|||||||
|
|
||||||
# 1.2 调用生图
|
# 1.2 调用生图
|
||||||
resp = await client.generate_image(prompt=final_prompt, size=f"{req.width}x{req.height}")
|
resp = await client.generate_image(prompt=final_prompt, size=f"{req.width}x{req.height}")
|
||||||
obs_urls = await client.download_and_upload_to_obs(resp)
|
# 定义Logo路径
|
||||||
|
LOGO_PATH = r"d:\dsWork\aiData\static\Images\login_logo.png"
|
||||||
|
obs_urls = await client.download_and_upload_to_obs(resp, overlay_logo_path=LOGO_PATH)
|
||||||
if not obs_urls:
|
if not obs_urls:
|
||||||
raise Exception("未获取到有效的图片URL")
|
raise Exception("未获取到有效的图片URL")
|
||||||
return obs_urls[0]
|
return obs_urls[0]
|
||||||
|
|||||||
@@ -363,12 +363,13 @@ class BananaClient:
|
|||||||
else:
|
else:
|
||||||
logger.info("未找到有效的图片 URL")
|
logger.info("未找到有效的图片 URL")
|
||||||
|
|
||||||
async def download_and_upload_to_obs(self, response_json):
|
async def download_and_upload_to_obs(self, response_json, overlay_logo_path=None):
|
||||||
"""
|
"""
|
||||||
异步从临时图片URL下载图片并直接上传到OBS(不落盘)
|
异步从临时图片URL下载图片并直接上传到OBS(不落盘)
|
||||||
|
|
||||||
参数:
|
参数:
|
||||||
response_json: API 响应的 JSON 数据
|
response_json: API 响应的 JSON 数据
|
||||||
|
overlay_logo_path: 水印Logo图片路径(可选)
|
||||||
|
|
||||||
返回:
|
返回:
|
||||||
uploaded_urls: 上传到OBS的图片URL列表
|
uploaded_urls: 上传到OBS的图片URL列表
|
||||||
@@ -414,6 +415,53 @@ class BananaClient:
|
|||||||
image_data = await response.read()
|
image_data = await response.read()
|
||||||
logger.debug(f"成功下载图片,大小: {len(image_data)} 字节")
|
logger.debug(f"成功下载图片,大小: {len(image_data)} 字节")
|
||||||
|
|
||||||
|
# 添加水印逻辑
|
||||||
|
if overlay_logo_path and os.path.exists(overlay_logo_path):
|
||||||
|
try:
|
||||||
|
from PIL import Image
|
||||||
|
import io
|
||||||
|
|
||||||
|
logger.info(f"正在添加水印: {overlay_logo_path}")
|
||||||
|
|
||||||
|
# 打开主图
|
||||||
|
img = Image.open(io.BytesIO(image_data))
|
||||||
|
|
||||||
|
# 打开Logo
|
||||||
|
logo = Image.open(overlay_logo_path)
|
||||||
|
|
||||||
|
# 计算Logo大小 (宽度为原图的20%)
|
||||||
|
target_logo_width = int(img.width * 0.2)
|
||||||
|
aspect_ratio = logo.height / logo.width
|
||||||
|
target_logo_height = int(target_logo_width * aspect_ratio)
|
||||||
|
|
||||||
|
# 调整Logo大小
|
||||||
|
logo = logo.resize((target_logo_width, target_logo_height), Image.Resampling.LANCZOS)
|
||||||
|
|
||||||
|
# 计算位置 (左上角,3% padding)
|
||||||
|
padding = int(img.width * 0.03)
|
||||||
|
position = (padding, padding)
|
||||||
|
|
||||||
|
# 粘贴Logo (处理透明度)
|
||||||
|
if logo.mode in ('RGBA', 'LA') or (logo.mode == 'P' and 'transparency' in logo.info):
|
||||||
|
img.paste(logo, position, logo)
|
||||||
|
else:
|
||||||
|
img.paste(logo, position)
|
||||||
|
|
||||||
|
# 保存回bytes
|
||||||
|
output_buffer = io.BytesIO()
|
||||||
|
# 保持原格式,如果无法识别则使用PNG
|
||||||
|
save_format = img.format if img.format else 'PNG'
|
||||||
|
img.save(output_buffer, format=save_format)
|
||||||
|
image_data = output_buffer.getvalue()
|
||||||
|
|
||||||
|
logger.info("水印添加成功")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"添加水印失败: {e}")
|
||||||
|
# 失败后继续上传原图
|
||||||
|
|
||||||
|
# 直接上传到OBS(不落盘)
|
||||||
|
|
||||||
# 直接上传到OBS(不落盘)
|
# 直接上传到OBS(不落盘)
|
||||||
logger.info(f"正在上传到OBS: {obs_key}")
|
logger.info(f"正在上传到OBS: {obs_key}")
|
||||||
success, result = self.obs_uploader.upload_base64_image(
|
success, result = self.obs_uploader.upload_base64_image(
|
||||||
|
|||||||
Reference in New Issue
Block a user