Performance considerations
View SourceInput
Pyramid TIF
The performance is greatly improved if you provide your images in more than one resolution. This can be accomplished by providing image pyramids. Using vips8 you can generate a TIF file pyramid by running.
vips tiffsave input.jpg output_pyramid.tif --compression deflate --tile --tile-width 256 --tile-height 256 --pyramid
The same can be achieved in Elixir with Vix:
{:ok, file} = Image.new_from_file("input.jpg")
Operation.tiffsave(file, "output_pyramid.tif",
pyramid: true,
"tile-height": 256,
"tile-width": 256,
tile: true,
compression: :VIPS_FOREIGN_TIFF_COMPRESSION_DEFLATE
)
This will generate a single file that contains multiple pages of decreasing resolution of the base image:
The IIIF Image plug will automatically evaluate these pages. If a downscaled version of the image is being requested, the plug will automatically pick the next highest resolution page for the requested scale (instead of always scaling down based on the maximum resolution).
Output
TIF
If you want to allow the user to request tif files, be aware these can not be streamed and are currently buffered in memory before they are sent to the client. This might cause memory issues for very large files.
Alternatives to this plug
This plug aims to implement the "level 2" compliance for the IIIF image API.
If you only want to provide "level 0" data (the most basic required for tiled viewers), you can preprocess your input images beforehand and serve them as static assets (without this library). There exist several resources on how to do this.
Working with vips, you can run:
vips dzsave input.jpg preprocessed_out --layout iiif3 --depth onetile --overlap 0 --suffix .jpg
This will create a directory "preprocessed_out" that contains a bunch of directories (each corresponding to a possible "region" parameter) and a info.json
file. These can be served as static assets. You would need to update the "id" value to match your service:
{
"@context": "http://iiif.io/api/image/3/context.json",
"id": "https://example.com/iiif/preprocessed_out",
"type": "ImageService3",
"profile": "level0",
"protocol": "http://iiif.io/api/image",
"tiles": [
{
"scaleFactors": [
1,
2,
4
],
"width": 512
}
],
"width": 3000,
"height": 2279
}
Again, Vix provides the same functionality in Elixir with Vix.Vips.Operation.dzsave/3.