【问题标题】:How do I get the number of frames from a gif file in python 3.8.6?如何从 python 3.8.6 中的 gif 文件中获取帧数?
【发布时间】:2021-02-16 06:19:11
【问题描述】:

我正在尝试从 gif 文件夹中加载 gif,该文件夹由 txt 文档上的数字选择。它正在选择正确的,但我不知道如何从选定的 gif 中获取帧数。 到目前为止的代码如下:

    from tkinter import *
    from PIL import Image, ImageTk
    from time import sleep
    import os

    root = Tk()
    root.title("displaygif")
    root.geometry("404x484")

    with open('wantedgif/wantedgif.txt') as wantedgif:        #This is the file where the ID for the gif is
        gifID = wantedgif.readline(3)
        print (gifID)

    line_number = 0
    with open("CodeRef/gifIDList.txt", 'r') as read_obj:    #This is the file that has the ID and what 
                                                             the gif names are, under there respective ID
        for line in read_obj:
            line_number += 1
                if gifID in line:
                line_number -= 1
                gif = read_obj.readlines()
                print(gif[line_number])                     #This all seems to work fine

    im = Image.open('gif/' + gif[line_number].strip() + '.gif')    #Opens the gif using the gif name

我不知道如何计算 gif 中的帧数,以及如何显示它。我已经搜索了几个小时,但找不到任何有用的东西。最好不要导入其他任何东西,但这并不重要。提前致谢。

【问题讨论】:

  • 所以你发布的代码实际上与你的实际问题基本无关?
  • 怎么会这样?
  • 你正在从文本文件中读取一堆标签;这些操作与您询问的问题完全无关。

标签: python tkinter python-imaging-library


【解决方案1】:

您可以使用im.n_frames 获取 GIF 图片内的帧数。

【讨论】:

    猜你喜欢
    • 2012-03-24
    • 2019-04-21
    • 2012-09-29
    • 1970-01-01
    • 2011-03-29
    • 2011-11-22
    • 2014-12-22
    • 2019-08-15
    • 2019-01-02
    相关资源
    最近更新 更多