Skip to content

Instantly share code, notes, and snippets.

@dyf
Created April 14, 2017 03:49
Show Gist options
  • Save dyf/7055eda65d33dc7e4b32af5b4dcaf445 to your computer and use it in GitHub Desktop.
Save dyf/7055eda65d33dc7e4b32af5b4dcaf445 to your computer and use it in GitHub Desktop.
jupyter gif
import requests
import shutil
from IPython.display import HTML
url = 'https://media.giphy.com/media/demgpwJ6rs2DS/giphy.gif'
file_name = 'img.gif'
# download
response = requests.get(url, stream=True)
with open(file_name, 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
# encode
blob = open(file_name, 'rb').read()
blob = blob.encode('base64')
# show
IMG_TAG = """<img src="data:image/gif;base64,{0}" alt="some_text">"""
img = IMG_TAG.format(blob)
HTML(img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment