# `Image.Plug.Provider.IIIF.InfoJson`
[🔗](https://github.com/elixir-image/image_plug/blob/v0.1.0/lib/image/plug/provider/iiif/info_json.ex#L1)

Builds the IIIF Image API 3.0 [Image Information document](https://iiif.io/api/image/3.0/#5-image-information)
(`info.json`) for a given source.

The info document describes what the server can do with this
particular image: its full pixel dimensions, the qualities and
formats it can deliver, the spec features it supports, and the
compliance level. Clients fetch info.json before issuing any
image request to learn what URLs they're allowed to construct.

This module is invoked by `Image.Plug` when an IIIF provider
recognises an `info.json` request. The provider tags the request
with `:json` output; the plug routes to `build/2` instead of the
normal pipeline interpreter.

### Compliance

Targets [IIIF Image API 3.0 Compliance Level 2](https://iiif.io/api/image/3.0/compliance/).
The advertised `extraFeatures`, `extraQualities`, and `extraFormats`
reflect what `Image.Plug.Provider.IIIF.Options` can parse and what
`Image.Plug.Capabilities` confirms libvips can encode.

# `build`

```elixir
@spec build(
  String.t(),
  {pos_integer(), pos_integer()}
) :: map()
```

Builds an info.json map for the given source dimensions.

### Arguments

* `id` is the absolute URL the info.json document is served from
  *without* the trailing `/info.json` segment. Per the spec, this
  is the image's canonical identifier URL.

* `dimensions` is `{width, height}` of the source image, in
  pixels.

### Returns

* A plain Elixir map ready to be serialised with `:json.encode/1`.

### Examples

    iex> info = Image.Plug.Provider.IIIF.InfoJson.build(
    ...>   "https://iiif.example.org/iiif/3/cat.jpg",
    ...>   {1024, 768}
    ...> )
    iex> info["@context"]
    "http://iiif.io/api/image/3/context.json"
    iex> info["width"]
    1024
    iex> info["height"]
    768
    iex> info["protocol"]
    "http://iiif.io/api/image"

---

*Consult [api-reference.md](api-reference.md) for complete listing*
