Skip to content

Commit

Permalink
Merge pull request #38 from mejackreed/add-quality-param
Browse files Browse the repository at this point in the history
Adds quality param for more IIIF compliance
  • Loading branch information
mejackreed committed May 3, 2016
2 parents b6d7410 + c8a118d commit 14fa84e
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Option | Type | Default | Description
`tileFormat` | `String` | `'jpg'` | The [format](http://iiif.io/api/image/2.0/#format) of the returned image.
`tileSize` | Number | 256 | Tile size (width and height in pixels, assuming tiles are square).
`fitBounds` | Boolean | true | Automatically center and fit the maps bounds to the added IIIF layer
`quality` | String | 'default' | [determines whether the image is delivered in color, grayscale or black and white](http://iiif.io/api/image/2.0/#quality) _Note:_ All IIIF servers do not support this parameter.

### Development

Expand Down
10 changes: 8 additions & 2 deletions examples/iiif-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ apostle = L.tileLayer.iiif('http://ids.lib.harvard.edu/ids/iiif/25286610/info.js
bnf = L.tileLayer.iiif('http://gallica.bnf.fr/iiif/ark:/12148/btv1b84539771/f1/info.json', {
attribution: '<a href="http://gallicalabs.bnf.fr/ark:/12148/btv1b84539771">ManuscritKalîla et Dimna, avec de nombreuses',
fitBounds: false
})
});

acrobata = L.tileLayer.iiif('http://libimages.princeton.edu/loris2/pudl0033/2007/04003/00000001.jp2/info.json', {
attribution: '<a href="http://pudl.princeton.edu/objects/pz50gw22j">Acrobata Marroquí - Lorenzo Homar</a>',
quality: 'gray'
});

iiifLayers = {
'Martin Luther King Jr. & Joan Baez ...': stanfordMlk,
'The provinces of New York and N...': princetonMap,
'Apostle: Anonymous sculptor of Fl...': apostle,
'ManuscritKalîla et Dimna, avec de...': bnf
'ManuscritKalîla et Dimna, avec de...': bnf,
'Acrobata Marroquí': acrobata
};

L.control.layers(iiifLayers).addTo(map);
37 changes: 25 additions & 12 deletions leaflet-iiif.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ L.TileLayer.Iiif = L.TileLayer.extend({
_this.y = data.height;
_this.x = data.width;

var profile,
tierSizes = [],
var tierSizes = [],
imageSizes = [],
scale,
width_,
Expand All @@ -131,19 +130,13 @@ L.TileLayer.Iiif = L.TileLayer.extend({

// Set quality based off of IIIF version
if (data.profile instanceof Array) {
profile = data.profile[0];
_this.profile = data.profile[0];
}else {
profile = data.profile;
}
switch (true) {
case /^http:\/\/library.stanford.edu\/iiif\/image-api\/1.1\/compliance.html.*$/.test(profile):
_this.quality = 'native';
break;
case /^http:\/\/iiif.io\/api\/image\/2.*$/.test(profile):
_this.quality = 'default';
break;
_this.profile = data.profile;
}

_this._setQuality();

// Unless an explicit tileSize is set, use a preferred tileSize
if (!_this.explicitTileSize) {
if (data.tiles) {
Expand Down Expand Up @@ -188,6 +181,26 @@ L.TileLayer.Iiif = L.TileLayer.extend({
_this._infoDeferred.resolve();
});
},

_setQuality: function() {
var _this = this;

// Quality already specified by consumer
if (_this.options.quality) {
return;
}

// Set the quality based on the IIIF compliance level
switch (true) {
case /^http:\/\/library.stanford.edu\/iiif\/image-api\/1.1\/compliance.html.*$/.test(_this.profile):
_this.options.quality = 'native';
break;
case /^http:\/\/iiif.io\/api\/image\/2.*$/.test(_this.profile):
_this.options.quality = 'default';
break;
}
},

_infoToBaseUrl: function() {
return this._infoUrl.replace('info.json', '');
},
Expand Down
32 changes: 32 additions & 0 deletions spec/LTileLayerIiifSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,36 @@ describe('L.TileLayer.Iiif', function() {
});
});
});

describe('quality', function() {
var iiifLayer;

it('by default is on', function(done) {
iiifLayer = L.tileLayer.iiif('http://localhost:9876/base/fixtures/acrobat_info.json');
map.addLayer(iiifLayer);
iiifLayer.on('load', function() {
expect(iiifLayer.options.quality).toBe('default');
done();
});
});

it('can be specified', function(done) {
iiifLayer = L.tileLayer.iiif('http://localhost:9876/base/fixtures/acrobat_info.json', {
quality: 'gray'
});
map.addLayer(iiifLayer);
iiifLayer.on('load', function() {
expect(iiifLayer.options.quality).toBe('gray');
done();
});
});

it('for a 1.1 compliance', function() {
iiifLayer = L.tileLayer.iiif('http://localhost:9876/base/fixtures/statue_info.json');
iiifLayer.on('load', function() {
expect(iiifLayer.options.quality).toBe('native');
done();
});
});
});
});
80 changes: 80 additions & 0 deletions spec/fixtures/acrobat_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"profile": [
"http://iiif.io/api/image/2/level2.json",
{
"supports": [
"canonicalLinkHeader",
"profileLinkHeader",
"mirroring",
"rotationArbitrary",
"sizeAboveFull"
],
"qualities": [
"default",
"bitonal",
"gray",
"color"
],
"formats": [
"jpg",
"png",
"gif",
"webp"
]
}
],
"tiles": [
{
"width": 1024,
"scaleFactors": [
1,
2,
4,
8,
16,
32,
64,
128
]
}
],
"protocol": "http://iiif.io/api/image",
"sizes": [
{
"width": 44,
"height": 57
},
{
"width": 88,
"height": 113
},
{
"width": 175,
"height": 225
},
{
"width": 350,
"height": 450
},
{
"width": 700,
"height": 900
},
{
"width": 1399,
"height": 1800
},
{
"width": 2797,
"height": 3600
},
{
"width": 5594,
"height": 7200
}
],
"height": 7200,
"width": 5594,
"@context": "http://iiif.io/api/image/2/context.json",
"@id": "http://libimages.princeton.edu/loris2/pudl0033%2F2007%2F04003%2F00000001.jp2"
}
23 changes: 23 additions & 0 deletions spec/fixtures/statue_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"@context": "http://library.stanford.edu/iiif/image-api/1.1/context.json",
"@id": "http://ids.lib.harvard.edu/ids/iiif/25286610",
"width": 4132,
"height": 8176,
"scale_factors": [
1,
2,
4,
8,
16,
32
],
"tile_width": 1024,
"tile_height": 1024,
"formats": [
"jpg"
],
"qualities": [
"native"
],
"profile": "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1"
}

0 comments on commit 14fa84e

Please sign in to comment.