Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何在Python中合并图像和Gif_Python 3.x_Python Imaging Library - Fatal编程技术网

Python 3.x 如何在Python中合并图像和Gif

Python 3.x 如何在Python中合并图像和Gif,python-3.x,python-imaging-library,Python 3.x,Python Imaging Library,我得到了一个部分透明的图像和一个GIF 我想用PIL将图像粘贴到GIF上,我得到一个动画GIF作为背景,前景是静态图像。您可能需要为自己的特定图像调整此设置,但这里是一个起点- from PIL import Image, ImageSequence transparent_foreground = Image.open(...) animated_gif = Image.open(...) frames = [] for frame in ImageSequence.Iterator(ani

我得到了一个部分透明的图像和一个GIF


我想用PIL将图像粘贴到GIF上,我得到一个动画GIF作为背景,前景是静态图像。

您可能需要为自己的特定图像调整此设置,但这里是一个起点-

from PIL import Image, ImageSequence
transparent_foreground = Image.open(...)
animated_gif = Image.open(...)

frames = []
for frame in ImageSequence.Iterator(animated_gif):
    frame = frame.copy()
    frame.paste(transparent_foreground, mask=transparent_foreground)
    frames.append(frame)
frames[0].save('output.gif', save_all=True, append_images=frames[1:])

您可能需要针对自己的特定图像进行调整,但这里是一个起点-

from PIL import Image, ImageSequence
transparent_foreground = Image.open(...)
animated_gif = Image.open(...)

frames = []
for frame in ImageSequence.Iterator(animated_gif):
    frame = frame.copy()
    frame.paste(transparent_foreground, mask=transparent_foreground)
    frames.append(frame)
frames[0].save('output.gif', save_all=True, append_images=frames[1:])