1

嗨,我有以下代码

    @hug.get('/getgif', output=hug.output_format.image('gif'))
    def get(username: str, password: str):
        dir_path = os.path.dirname(__file__)
        img_path = os.path.join(dir_path, 'animation.gif')
        img = Image.open(img_path)
        return img

我正在使用拥抱、python3 和 PIL 来创建响应。返回到我的浏览器的图像根本没有动画。我猜 PIL 只获取 GIF 图像的第一帧并返回它。有没有其他方法可以将整个 GIF 图像流回浏览器?

4

1 回答 1

0

您不需要使用 PIL 加载 gif。您只需为函数提供正确的输出格式并返回图像的文件路径。看看这个例子:

@hug.get('/images', output=hug.output_format.file)
def get_image(name: str):
    img_file = os.path.join(IMG_ROOT_DIR, name) # type: str
    return img_file
于 2017-05-15T18:44:50.680 回答