【问题标题】:Having problem with merging image and gif(Inversed(or blue) images) discord.py合并图像和 gif(反转(或蓝色)图像)discord.py 时出现问题
【发布时间】:2021-05-27 04:30:56
【问题描述】:
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"、"palette" 和其他一些东西,但这并没有真正的帮助

【问题讨论】:

  • 好的,这不是倒置的,我没有考虑周到,因为第一张和第二张图片的颜色与 gif 相同(如黄色墙壁或蓝色地板)

标签: python discord.py python-imaging-library


【解决方案1】:

好的,我在 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') - 这就是解决方案

【讨论】:

    猜你喜欢
    • 2023-04-04
    • 2011-09-05
    • 1970-01-01
    • 2011-12-13
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 1970-01-01
    • 2016-06-08
    相关资源
    最近更新 更多