CI status

IIIF Image Plug

An Elixir plug implementing the International Image Interoperability Framework (IIIF) image API specification.

Installation

The package can be installed by adding iiif_image_plug to your list of dependencies in mix.exs:

def deps do
[
{:iiif_image_plug, "~> 0.3.0"}
]
end

Usage

Assuming you want to serve IIIF in your plug based server at "/iiif/v3", add a forward route like this:

forward("/iiif/v3",
to: IIIFImagePlug.V3,
init_opts: %{
identifier_to_path_callback: &ImageStore.identifier_to_path/1
}
)

Phoenix

For Phoenix it would look slightly different:

forward("/iiif/v3", IIIFImagePlug.V3, %{
identifier_to_path_callback: &ImageStore.identifier_to_path/1
})

The option :identifier_to_path_callback lets the plug map the IIIF identifier to an actual file path in your file system.

ImageStore.identifier_to_path/1 in this case might look something like this:

def identifier_to_path(identifier) do
"/mnt/my_app_images/#{identifier}"
end

A GET request /iiif/v3/sample_image.jpg/info.json would then cause the plug to look for an image file at /mnt/my_app_images/sample_image.jpg and return its metadata.

For the complete list of plug options have a look at the module documentation.

Development

This repository comes with a minimalistic server, run the server with:

iex -S mix run

The metadata of the main sample file can now be accessed at http://127.0.0.1:4000/bentheim.jpg/info.json:

{
"id": "http://localhost:4000/bentheim.jpg",
"profile": "level2",
"type": "ImageServer3",
"protocol": "http://iiif.io/api/image",
"rights": "https://creativecommons.org/publicdomain/zero/1.0/",
"width": 3000,
"height": 2279,
"@context": "http://iiif.io/api/image/3/context.json",
"maxHeight": 10000,
"maxWidth": 10000,
"maxArea": 100000000,
"extra_features": [
"mirroring",
"regionByPct",
"regionByPx",
"regionSquare",
"rotationArbitrary",
"sizeByConfinedWh",
"sizeByH",
"sizeByPct",
"sizeByW",
"sizeByWh",
"sizeUpscaling"
],
"preferredFormat": [
"jpg"
],
"extraFormats": [
"webp",
"png",
"tif"
],
"extraQualities": [
"color",
"gray",
"bitonal"
]
}

The image data of the sample file can be viewed at http://127.0.0.1:4000/bentheim.jpg/full/max/0/default.jpg and you are able to play around with the IIIF API parameters.