Mercurial > hg > digilib
changeset 1452:9429bb9c3a42
more IIIF API support (expose size of prescaled images).
author | robcast |
---|---|
date | Thu, 12 Nov 2015 16:43:01 +0100 |
parents | f0947c6190e6 |
children | e7d94cfbec0b 0f276f0cc556 |
files | common/src/main/java/digilib/io/ImageSet.java doc/src/site/markdown/iiif-api.md servlet/src/main/java/digilib/servlet/ServletOps.java |
diffstat | 3 files changed, 36 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/common/src/main/java/digilib/io/ImageSet.java Thu Nov 12 15:00:16 2015 +0100 +++ b/common/src/main/java/digilib/io/ImageSet.java Thu Nov 12 16:43:01 2015 +0100 @@ -35,6 +35,9 @@ /** * Set of ImageInputs of the same image in different resolutions. * + * The images are be added in the order of higher to lower resolutions. + * The first image is considered the hires "original". + * * @author casties */ public class ImageSet { @@ -101,11 +104,10 @@ * @return */ public ImageInput getNextSmaller(ImageSize size) { - for (ListIterator<ImageInput> i = getHiresIterator(); i.hasNext();) { - ImageInput f = i.next(); - ImageSize is = f.getSize(); + for (ImageInput i : list) { + ImageSize is = i.getSize(); if (is != null && is.isTotallySmallerThan(size)) { - return f; + return i; } } return null;
--- a/doc/src/site/markdown/iiif-api.md Thu Nov 12 15:00:16 2015 +0100 +++ b/doc/src/site/markdown/iiif-api.md Thu Nov 12 16:43:01 2015 +0100 @@ -2,23 +2,23 @@ The Scaler servlet provides not only its native [Scaler API](scaler-api.html) but also an API compliant to the standards of the International Image Interoperability Framework http://iiif.io. -As of version 2.3 digilib supports the [IIIF Image API version 1.1](http://iiif.io/api/image/1.1/) at [compliance level 2](http://iiif.io/api/image/1.1/compliance.html) (since V2.3.3 even for forced w,h sizes where the image will be distorted). +As of version 2.3.6 digilib supports the [IIIF Image API version 2](http://iiif.io/api/image/2.0/) at [compliance level 2](http://iiif.io/api/image/2.0/compliance.html) (except bitonal quality). You can switch between API version 1.1 and 2.0 support with the `iiif-api-version` parameter in [digilib-config](digilib-config.html), IIIF Image API URLs for an image request have the form: - http[s]://server/digilib-webapp/Scaler/iiif-prefix/identifier/region/size/rotation/quality[.format] + http[s]://{server}/{digilib-webapp}/Scaler/{iiif-prefix}/{identifier}/{region}/{size}/{rotation}/{quality}.{format} where `digilib-webapp` is the name of the digilib web application in the servlet container. -The value of `iiif-prefix` is defined by the `iiif-prefix` parameter in the [digilib-config](digilib-config.html). The default value is "IIIF". +The value of `iiif-prefix` is defined by the `iiif-prefix` parameter in [digilib-config](digilib-config.html). The default value is "IIIF". The `identifier` part of the URL must not contain slashes. Since the identifier is mapped to the digilib fn-parameter, which is a filesystem path that likely contains slashes separating subdirectories, all occurrences of a slash have to be replaced by the value of the `iiif-slash-replacement` parameter in [digilib-config](digilib-config.html). The default value of the replacement string is "!", so the fn-path "books/book1/page0002" becomes the identifier "books!book1!page0002". -For a definition of the other request parameters `region`, `size`, `rotation`, `quality`, and `format` please see the [IIIF Image API docs](http://iiif.io/api/image/1.1/). +For a definition of the other parameters `region`, `size`, `rotation`, `quality`, and `format` please see the [IIIF Image API docs](http://iiif.io/api/image/2.0/). A IIIF Image API image request URL could look like: - http://www.example.org/digilib/Scaler/IIIF/books!book1!page0002/full/!150,75/0/native.jpg + http://www.example.org/digilib/Scaler/IIIF/books!book1!page0002/full/!150,75/0/default.jpg An info request URL for the same image looks like:
--- a/servlet/src/main/java/digilib/servlet/ServletOps.java Thu Nov 12 15:00:16 2015 +0100 +++ b/servlet/src/main/java/digilib/servlet/ServletOps.java Thu Nov 12 16:43:01 2015 +0100 @@ -47,6 +47,7 @@ import digilib.io.FileOpException; import digilib.io.FileOps; import digilib.io.ImageInput; +import digilib.io.ImageSet; import digilib.util.ImageSize; public class ServletOps { @@ -384,10 +385,11 @@ * get image size */ ImageSize size = null; + ImageSet imageSet = null; try { // get original image size - ImageInput img; - img = dlReq.getJobDescription().getImageSet().getBiggest(); + imageSet = dlReq.getJobDescription().getImageSet(); + ImageInput img = imageSet.getBiggest(); size = img.getSize(); } catch (FileOpException e) { try { @@ -429,6 +431,7 @@ +"; rel=\"http://www.w3.org/ns/json-ld#context\"" +"; type=\"application/ld+json\""); } + // write info.json writer = response.getWriter(); writer.println("{"); writer.println("\"@context\" : \"http://iiif.io/api/image/2/context.json\","); @@ -437,12 +440,26 @@ writer.println("\"width\" : " + size.width + ","); writer.println("\"height\" : " + size.height + ","); writer.println("\"profile\" : ["); - writer.println("\"http://iiif.io/api/image/2/level2.json\","); - writer.println("{"); - writer.println("\"formats\" : [\"jpg\", \"png\"],"); - writer.println("\"qualities\" : [\"color\", \"grey\"],"); - writer.println("\"supports\" : [\"mirroring\", \"rotationArbitrary\", \"sizeAboveFull\"],"); - writer.println("}]"); + writer.println(" \"http://iiif.io/api/image/2/level2.json\","); + writer.println(" {"); + writer.println(" \"formats\" : [\"jpg\", \"png\"],"); + writer.println(" \"qualities\" : [\"color\", \"gray\"],"); + writer.println(" \"supports\" : [\"mirroring\", \"rotationArbitrary\", \"sizeAboveFull\"]"); + writer.println(" }]"); + // add sizes of prescaled images + int numImgs = imageSet.size(); + if (numImgs > 1) { + writer.println(", \"sizes\" : ["); + for (int i = numImgs - 1; i > 0; --i) { + ImageInput ii = imageSet.get(i); + ImageSize is = ii.getSize(); + writer.println(" {\"width\" : "+is.getWidth()+", \"height\" : "+is.getHeight()+"}" + +((i > 1)?",":"")); + } + writer.println("]"); + } + writer.println("}"); + } else { /* * IIIF Image API version 1 image information