Skip to content

Instantly share code, notes, and snippets.

@cancan101
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cancan101/80e27feaef8eae0ed921 to your computer and use it in GitHub Desktop.
Save cancan101/80e27feaef8eae0ed921 to your computer and use it in GitHub Desktop.
OpenCV Load GIF URL
from PIL import Image
import requests
import tempfile
def load_gif_url(url):
with tempfile.NamedTemporaryFile(suffix=".gif") as f:
f.write(requests.get(url).content)
f.flush()
img = Image.open(f.name)
with tempfile.NamedTemporaryFile(suffix=".png") as f:
img.save(f.name)
f.flush()
src = cv2.imread(f.name)
assert src is not None and len(src), "Empty"
return src
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment