如何使用PIL将gif框架转换为用于数据uri的base64

问题描述

我有一个gif文件,我想提取它的帧并将每个帧转换为数据uri,但是我不知道如何在base64中对其进行编码。问题是(我猜)如何使用枕头访问每个帧的字节序列。 这是我的尝试:

from PIL import Image,ImageSequence


def get_imgs(gif):
    with Image.open(gif) as im:
        for frame in ImageSequence.Iterator(im):
            w,h = frame.size
            yield ('<img width="{}" height="{}" src="data:image/gif;base64,{}">'.format(w,h,str(base64.b64encode(frame.data()),"utf-8"))

但这在浏览器中不起作用。我很确定这是一件小事,因为我对PIL的了解很少。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)