Get Content-Length/Type with HEAD request
Before downloading an image, get the Content-Type and Content-Length by using HTTP HEAD request (GET without the actual data, just headers), then check if type is a usable image format and that the size is below a configurable limit.