1

Hi I have the following code

    @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

I am using hug, python3 and PIL to create a response. The image returned to my browser does not anmiate at all. I am guessing PIL only takes the first frame of the GIF image and return that. Is there any alternative to stream the whole GIF image back to browser?

Timothy Leung
  • 1,407
  • 7
  • 22
  • 39

1 Answers1

0

You don't need to load the gif with PIL. You just have to give the function the right output-format and return the file path of the image. Have a look at this example:

@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
Rotareti
  • 49,483
  • 23
  • 112
  • 108