Dims

Probe remote image dimensions (width × height) from just a URL — without downloading the image.

Image formats keep their dimensions in the file header, so Dims fetches only the first ~128 KB via an HTTP Range request, parses the JPEG / PNG / WebP / GIF header, and discards the bytes. Milliseconds and a few KB per image instead of megabytes.

Dims.probe("https://cdn.example.com/page1.jpg")
#=> %{width: 800, height: 8000}
Dims.probe_all(urls)
#=> [%{url: ..., width: 800, height: 1200}, ...] # input order preserved

Useful anywhere you deal with images you don't host: reserving layout space (aspect-ratio, <img width height>) before anything loads, link previews, gallery imports, comic/manga readers deciding page layouts, CMS ingestion.


Install

def deps do
[
{:dims, "~> 0.1"}
]
end

Batch probing, built for the real world

Options

Dims.probe(url,
headers: [{"referer", "https://source.example/"}], # CDNs that check referers
headers_fun: &MyApp.headers_for/1, # per-URL headers
probe_bytes: 131_071,
receive_timeout: 8_000,
cache: true,
cache_ttl: :timer.hours(24 * 30)
)

Batch calls also take :max_concurrency, :sample_size, and :full_threshold.

Parsing bytes you already have

Dims.Parser.parse/1 is the pure header parser — hand it the leading bytes of an upload or a cached chunk and get %{width:, height:} back with no I/O.

Formats

JPEG (all SOFn markers, so progressive too), PNG, WebP (VP8 / VP8L / VP8X), GIF (87a/89a).

License

MIT