Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 返回带有拥抱API的GIF图像(图像在浏览器上不动画)_Python_Web Services_Gif_Hug - Fatal编程技术网

Python 返回带有拥抱API的GIF图像(图像在浏览器上不动画)

Python 返回带有拥抱API的GIF图像(图像在浏览器上不动画),python,web-services,gif,hug,Python,Web Services,Gif,Hug,嗨,我有以下代码 @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_pa

嗨,我有以下代码

    @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图像流回到浏览器

您不需要用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

您不需要用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