我可以通过先保存数据将 gif 编码为 Base64。
imageio.mimsave(output_fn, [img_as_ubyte(frame) for frame in gif], fps=original_fps)
with open(output_fn, "rb") as gif_file:
detect_base64 = 'data:image/gif;base64,{}'.format(base64.b64encode(gif_file.read()).decode())
我需要找到一种方法以图像数组的形式对上面的
gif
进行编码,并将相应的fps
编码为base64,而不需要先将其保存到output_fn
中。
一般方法是使用
BytesIO
来替代打开的文件,即
gif_file = io.BytesIO()
imageio.mimsave(gif_file, [img_as_ubyte(frame) for frame in gif], 'GIF', fps=original_fps)
detect_base64 = 'data:image/gif;base64,{}'.format(base64.b64encode(gif_file.getvalue()).decode())