This is an implementation of the excellent Ruby library FastImage - but for Python.
FastImage finds the size or type of an image given its uri by fetching as little as needed.
pip install fastimage
Usage is pretty dang simple.
import asyncio
from fastimage.detect import get_size
loop = asyncio.get_event_loop()
url = "http://stephensykes.com/images/ss.com_x.gif"
width, height = loop.run_until_complete(get_size(url))
print("Size:", width, "x", height)
which will poop out:
Size: 266 x 56
You can also just get the image type:
import asyncio
from fastimage.detect import get_type
loop = asyncio.get_event_loop()
url = "http://stephensykes.com/images/ss.com_x.gif"
result = loop.run_until_complete(get_type(url))
print("Type:", result)
which will poop out:
Type: gif
Right now, sizes can be deduced from webp / gif / jpg / png. Additionally, it can detect the type (but not size) of bmp / tiff.