合并图像和 gif(反转(或蓝色)图像)时出现问题 discord.py
Having problem with merging image and gif(Inversed(or blue) images) discord.py
avatar1 = ctx.author.avatar_url_as(size = 128) #author
avatar2 = member.avatar_url_as(size = 128) #member
gif = Image.open('images\spanking.gif')
#
data = BytesIO(await avatar1.read())
pfp = Image.open(data).convert('RGBA')
pfp = pfp.resize((105,105))
pfp = pfp.rotate(-30,fillcolor = 0)
x,y = 166,64
#
data2 = BytesIO(await avatar2.read())
pfp2 = Image.open(data2).convert('RGBA')
pfp2 = pfp2.resize((64,64))
x2,y2 = 173,257
frames = []
for frame in ImageSequence.Iterator(gif):
frame = frame.copy()
frame.paste(pfp,(x,y),pfp)
x+=3 # face movenment
y+=3 #
frame.paste(pfp2,(x2,y2))
frames.append(frame)
frames[0].save('probagif1.gif',save_all = True, append_images=frames[1:])
我正在使用 gif 制作有趣的 discord bot 命令,但是当我将图像与 gif 帧合并并保存 gif 时:每张图像都是反转的(或只是蓝色的),我尝试使用 PIL save() 选项像“include_color_table”、“调色板”和其他一些东西,但这并没有真正帮助
好的,我在 github 上找到并回答了,感谢 radarhere(https://github.com/python-pillow/Pillow/issues/3629) 如果有人遇到同样的问题,解决方案是将帧转换为与您合并的图像相同的类型。
for frame in ImageSequence.Iterator(gif):
frame = frame.copy()
frame = frame.convert('RGBA') # Thats it
frame.paste(pfp,(x,y),pfp)
x+=2 # face movenment
y+=2 #
frame.paste(pfp2,(x2,y2),pfp2)
x2-=1 # same
y2-=1 #
frames.append(frame)
frames[0].save('probagif1.gif',save_all = True, append_images=frames[1:])
frame = frame.convert('RGBA') - 这就是解决方案
avatar1 = ctx.author.avatar_url_as(size = 128) #author
avatar2 = member.avatar_url_as(size = 128) #member
gif = Image.open('images\spanking.gif')
#
data = BytesIO(await avatar1.read())
pfp = Image.open(data).convert('RGBA')
pfp = pfp.resize((105,105))
pfp = pfp.rotate(-30,fillcolor = 0)
x,y = 166,64
#
data2 = BytesIO(await avatar2.read())
pfp2 = Image.open(data2).convert('RGBA')
pfp2 = pfp2.resize((64,64))
x2,y2 = 173,257
frames = []
for frame in ImageSequence.Iterator(gif):
frame = frame.copy()
frame.paste(pfp,(x,y),pfp)
x+=3 # face movenment
y+=3 #
frame.paste(pfp2,(x2,y2))
frames.append(frame)
frames[0].save('probagif1.gif',save_all = True, append_images=frames[1:])
我正在使用 gif 制作有趣的 discord bot 命令,但是当我将图像与 gif 帧合并并保存 gif 时:每张图像都是反转的(或只是蓝色的),我尝试使用 PIL save() 选项像“include_color_table”、“调色板”和其他一些东西,但这并没有真正帮助
好的,我在 github 上找到并回答了,感谢 radarhere(https://github.com/python-pillow/Pillow/issues/3629) 如果有人遇到同样的问题,解决方案是将帧转换为与您合并的图像相同的类型。
for frame in ImageSequence.Iterator(gif):
frame = frame.copy()
frame = frame.convert('RGBA') # Thats it
frame.paste(pfp,(x,y),pfp)
x+=2 # face movenment
y+=2 #
frame.paste(pfp2,(x2,y2),pfp2)
x2-=1 # same
y2-=1 #
frames.append(frame)
frames[0].save('probagif1.gif',save_all = True, append_images=frames[1:])
frame = frame.convert('RGBA') - 这就是解决方案