使用python制作动图

利用python制作gif图

引言

当写文章时候,多张图片会影响排版,可以考虑制作gif图

准备

pip install imageio

代码

# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
import os

import imageio

if __name__ == '__main__':
    # 图片存放的地址
    path = r'D:\a\10'

    # 返回图片列表
    files = os.listdir(path)

    # 对图片按图片名称排序
    # 图片先后出现顺序根据名称 1.png 2.png ...据欸的那个
    files.sort(key=lambda x: int(x.split('.')[0]))

    picture_list = []
    for file in files:
        # 拼接图片路劲
        file_path = os.path.join(path, file)
        # 组装对象
        picture_list.append(imageio.v2.imread(file_path))

    # 生成gif 第一个参数代表名称 最后一个参数代表间隔,值越低,切换速度越慢
    imageio.mimsave("d.gif", picture_list, 'GIF', fps=0.2)

示例

image
image
image
image
image

posted @   异世界阿伟  阅读(465)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示