Skip to content

Commit

Permalink
feat: 对上传的图像去除第四通道
Browse files Browse the repository at this point in the history
  • Loading branch information
14790897 committed May 5, 2024
1 parent 89cf6e8 commit fea1846
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,19 @@ def generate_handwriting():
),
400,
)
background_image = Image.open(io.BytesIO(background_image.read()))
image_data = io.BytesIO(background_image.read())

# 使用 PIL 打开图像
try:
background_image = Image.open(image_data)

# 如果图像包含 Alpha 通道(模式为 'RGBA' 或 'LA'),则去除 Alpha 通道
if background_image.mode in ("RGBA", "LA"):
# 将图像转换为 'RGB' 模式
background_image = background_image.convert("RGB")

except IOError:
return jsonify({"status": "error", "message": "Invalid image format"}), 400

text_to_generate = data["text"]
if data["preview"] == "true":
Expand Down

0 comments on commit fea1846

Please sign in to comment.