2017-03-04 1 views
1

Hallo Ich habe den folgenden Codereturn GIF-Bild mit Hug API (Bild animiert nicht auf Browser)

@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 

Ich bin mit Umarmung, python3 und PIL eine Antwort zu erstellen. Das an meinen Browser zurückgegebene Bild wird überhaupt nicht angezeigt. Ich nehme an, PIL nimmt nur das erste Bild des GIF-Bildes und gibt das zurück. Gibt es eine Alternative, um das gesamte GIF-Bild zurück zum Browser zu streamen?

Antwort

0

Sie müssen das gif nicht mit PIL laden. Sie müssen der Funktion nur das richtige Ausgabeformat geben und den Dateipfad des Bildes zurückgeben. Schauen Sie sich dieses Beispiel an:

@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 
Verwandte Themen