修复了海报接受错误图像的问题
This commit is contained in:
parent
7224f46027
commit
b58bc3d232
Binary file not shown.
@ -214,19 +214,33 @@ class PosterService:
|
||||
|
||||
|
||||
# # 3. 图片解码
|
||||
try:
|
||||
# 移除可能存在的MIME类型前缀
|
||||
if images_base64.startswith("data:"):
|
||||
images_base64 = images_base64.split(",", 1)[1]
|
||||
|
||||
# 解码base64
|
||||
image_bytes = base64.b64decode(images_base64)
|
||||
|
||||
# 创建PIL Image对象
|
||||
images = Image.open(BytesIO(image_bytes))
|
||||
images = None
|
||||
# 获取模板的默认尺寸,如果获取不到则使用标准尺寸
|
||||
template_size = getattr(template_handler, 'size', (900, 1200))
|
||||
|
||||
if images_base64 and images_base64.strip():
|
||||
try:
|
||||
# 移除可能存在的MIME类型前缀
|
||||
if images_base64.startswith("data:"):
|
||||
images_base64 = images_base64.split(",", 1)[1]
|
||||
|
||||
# 解码base64
|
||||
image_bytes = base64.b64decode(images_base64)
|
||||
|
||||
# 创建PIL Image对象
|
||||
images = Image.open(BytesIO(image_bytes))
|
||||
logger.info("图片解码成功")
|
||||
|
||||
except Exception as e:
|
||||
print(f"解码失败: {e}")
|
||||
except Exception as e:
|
||||
logger.error(f"图片解码失败: {e}")
|
||||
# 创建一个与目标大小一致的纯黑底图
|
||||
images = Image.new('RGB', template_size, color='black')
|
||||
logger.info(f"创建默认黑色背景图,尺寸: {template_size}")
|
||||
else:
|
||||
logger.warning("未提供图片数据,使用默认黑色背景图")
|
||||
# 创建一个与目标大小一致的纯黑底图
|
||||
images = Image.new('RGB', template_size, color='black')
|
||||
logger.info(f"创建默认黑色背景图,尺寸: {template_size}")
|
||||
|
||||
# 4. 调用模板生成海报
|
||||
try:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user