python-3.x - 如何在 Python Pillow 中合并图像和 Gif
问题描述
我得到了一个部分透明的图像和一个 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:])
推荐阅读
- json - postgresql UPDATE 从 JSONB 数据类型中删除键/值
- delphi - “Samples\Object Pascal\Database\EMS\FireDACResource”示例如何工作?
- python-3.x - 根据日期的 where 子句查询 BigQuery
- c# - DbContext.SaveChangesAsync 的进展
- python - 如果@ in password 无法连接到Mysql
- rust - 如何复制不同类型但具有相同字段的结构类型(不是值)
- call - 使用记录方法调用记录应用程序,它在调用时启动,但应用程序实际上在没有记录方法的情况下开始工作
- c# - 以编程方式启用启动应用程序
- postgresql - 更新迁移后序列化种子数据
- c# - 如何在热敏打印机中打印二维码