♻️ 重构 pic2bytes 方法,当Image.format为空时自动回退为 PNG,并在处理 GIF 时保留所有动画帧。

This commit is contained in:
BalconyJH 2024-12-09 21:06:28 +08:00
parent 27393b1e93
commit beba7660e5
No known key found for this signature in database
GPG Key ID: FF602923BD2A1FAF

View File

@ -510,10 +510,13 @@ class BuildImage:
bytes: bytes
"""
buf = BytesIO()
if isinstance(self.markImg.format, str) and self.markImg.format.upper() in ["GIF"]:
img_format = self.markImg.format.upper() if self.markImg.format else "PNG"
if img_format == "GIF":
self.markImg.save(buf, format="GIF", save_all=True, loop=0)
return buf.getvalue()
self.markImg.save(buf, format="PNG")
else:
self.markImg.save(buf, format="PNG")
return buf.getvalue()
def convert(self, type_: ModeType) -> Self: