This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added thumbnails fixtures and update script
- Loading branch information
Showing
14 changed files
with
768 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
// Vitest Snapshot v1 | ||
|
||
exports[`Thumbnail helper > Thumbnail - Canvas with no thumbnail property - ImageService 1`] = ` | ||
[ | ||
{ | ||
"best": { | ||
"height": 512, | ||
"id": "https://iiif.io/api/image/2.1/example/reference/918ecd18c2592080851777620de9bcb5-fountain/full/512,/0/default.jpg", | ||
"type": "fixed", | ||
"unsafe": false, | ||
"width": 512, | ||
}, | ||
"fallback": [], | ||
"log": [], | ||
}, | ||
{ | ||
"best": { | ||
"height": 512, | ||
"id": "https://iiif.io/api/image/2.1/example/reference/918ecd18c2592080851777620de9bcb5-gottingen/full/512,/0/default.jpg", | ||
"type": "fixed", | ||
"unsafe": false, | ||
"width": 512, | ||
}, | ||
"fallback": [], | ||
"log": [], | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Thumbnail helper > Thumbnail - Canvas with no thumbnail property - level0 image 1`] = ` | ||
[ | ||
{ | ||
"best": { | ||
"height": 189, | ||
"id": "https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/level0/tractor/full/252,189/0/default.jpg", | ||
"type": "fixed", | ||
"unsafe": false, | ||
"width": 252, | ||
}, | ||
"fallback": [], | ||
"log": [], | ||
}, | ||
{ | ||
"best": { | ||
"height": 189, | ||
"id": "https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/level0/van/full/252,189/0/default.jpg", | ||
"type": "fixed", | ||
"unsafe": false, | ||
"width": 252, | ||
}, | ||
"fallback": [], | ||
"log": [], | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Thumbnail helper > Thumbnail - Canvas with no thumbnail property - simple image 1`] = ` | ||
[ | ||
{ | ||
"best": { | ||
"height": 4032, | ||
"id": "https://fixtures.iiif.io/images/Glen/photos/fountain.jpg", | ||
"type": "fixed", | ||
"unsafe": true, | ||
"width": 3024, | ||
}, | ||
"fallback": [], | ||
"log": [], | ||
}, | ||
{ | ||
"best": undefined, | ||
"fallback": [], | ||
"log": [], | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Thumbnail helper > Thumbnail - Canvases with thumbnail property which is an image URL 1`] = ` | ||
[ | ||
{ | ||
"best": { | ||
"height": 512, | ||
"id": "https://iiif.io/api/image/2.1/example/reference/15f769d62ca9a3a2deca390efed75d73-4_titlepage1_verso/full/512,/0/default.jpg", | ||
"type": "fixed", | ||
"unsafe": false, | ||
"width": 512, | ||
}, | ||
"fallback": [ | ||
{ | ||
"height": 7230, | ||
"id": "https://iiif.io/api/image/2.1/example/reference/15f769d62ca9a3a2deca390efed75d73-4_titlepage1_verso/full/full/0/default.jpg", | ||
"type": "fixed", | ||
"unsafe": true, | ||
"width": 5428, | ||
}, | ||
], | ||
"log": [], | ||
}, | ||
{ | ||
"best": { | ||
"height": 512, | ||
"id": "https://iiif.io/api/image/2.1/example/reference/15f769d62ca9a3a2deca390efed75d73-6_titlepage2_verso/full/512,/0/default.jpg", | ||
"type": "fixed", | ||
"unsafe": false, | ||
"width": 512, | ||
}, | ||
"fallback": [ | ||
{ | ||
"height": 7230, | ||
"id": "https://iiif.io/api/image/2.1/example/reference/15f769d62ca9a3a2deca390efed75d73-6_titlepage2_verso/full/full/0/default.jpg", | ||
"type": "fixed", | ||
"unsafe": true, | ||
"width": 5428, | ||
}, | ||
], | ||
"log": [], | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Thumbnail helper > Thumbnail - Canvases with thumbnail property which is an image URL with dimensions 1`] = ` | ||
[ | ||
{ | ||
"best": { | ||
"height": 512, | ||
"id": "https://iiif.io/api/image/2.1/example/reference/15f769d62ca9a3a2deca390efed75d73-4_titlepage1_verso/full/512,/0/default.jpg", | ||
"type": "fixed", | ||
"unsafe": false, | ||
"width": 512, | ||
}, | ||
"fallback": [ | ||
{ | ||
"height": 7230, | ||
"id": "https://iiif.io/api/image/2.1/example/reference/15f769d62ca9a3a2deca390efed75d73-4_titlepage1_verso/full/full/0/default.jpg", | ||
"type": "fixed", | ||
"unsafe": true, | ||
"width": 5428, | ||
}, | ||
], | ||
"log": [], | ||
}, | ||
{ | ||
"best": { | ||
"height": 512, | ||
"id": "https://iiif.io/api/image/2.1/example/reference/15f769d62ca9a3a2deca390efed75d73-6_titlepage2_verso/full/512,/0/default.jpg", | ||
"type": "fixed", | ||
"unsafe": false, | ||
"width": 512, | ||
}, | ||
"fallback": [ | ||
{ | ||
"height": 7230, | ||
"id": "https://iiif.io/api/image/2.1/example/reference/15f769d62ca9a3a2deca390efed75d73-6_titlepage2_verso/full/full/0/default.jpg", | ||
"type": "fixed", | ||
"unsafe": true, | ||
"width": 5428, | ||
}, | ||
], | ||
"log": [], | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Thumbnail helper > Thumbnail - Canvases with thumbnail property with level0 image service (Most optimised option) 1`] = ` | ||
[ | ||
{ | ||
"best": { | ||
"height": 452, | ||
"id": "https://iiif-commons.github.io/fixtures/examples/thumbnail/thum_prop/v2/canvas_thum_level0/titlepage1_verso/full/340,452/0/default.jpg", | ||
"type": "fixed", | ||
"unsafe": false, | ||
"width": 340, | ||
}, | ||
"fallback": [], | ||
"log": [], | ||
}, | ||
{ | ||
"best": { | ||
"height": 452, | ||
"id": "https://iiif-commons.github.io/fixtures/examples/thumbnail/thum_prop/v2/canvas_thum_level0/titlepage2_verso/full/340,452/0/default.jpg", | ||
"type": "fixed", | ||
"unsafe": false, | ||
"width": 340, | ||
}, | ||
"fallback": [], | ||
"log": [], | ||
}, | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { thumbnailFixtures } from '../fixtures'; | ||
import { expect, test } from 'vitest'; | ||
import { Vault } from '@iiif/vault'; | ||
import { createThumbnailHelper } from '../src/thumbnail'; | ||
import { readFile } from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { ManifestNormalized } from '@iiif/presentation-3'; | ||
|
||
describe('Thumbnail helper', function () { | ||
test.each(thumbnailFixtures as { label: string; description: string }[])(`Thumbnail - $label`, async (fixture) => { | ||
const vault = new Vault(); | ||
const helper = createThumbnailHelper(vault); | ||
const manifestJson: any = JSON.parse( | ||
(await readFile(path.join(process.cwd(), 'fixtures/thumbnails', `${fixture.label}.json`))).toString() | ||
); | ||
const manifest = await vault.load<ManifestNormalized>(manifestJson.id || manifestJson['@id']); | ||
|
||
if (!manifest) { | ||
expect.fail(`Invalid manifest`); | ||
} | ||
|
||
const thumbnails = []; | ||
for (const canvas of manifest.items) { | ||
thumbnails.push(helper.getBestThumbnailAtSize(canvas, { width: 256, height: 256 })); | ||
} | ||
|
||
expect(await Promise.all(thumbnails)).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Add thumbnail fixtures here. | ||
|
||
// @type any | ||
export const thumbnailFixtures = [ | ||
{ | ||
label: 'Canvas with no thumbnail property - ImageService', | ||
url: 'https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/image_service2/manifest.json', | ||
description: 'This is a manifest where there is no thumbnail property but the thumbnail can be generated from the image service.', | ||
}, | ||
{ | ||
label: 'Canvas with no thumbnail property - level0 image', | ||
url: 'https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/level0/manifest.json', | ||
description: 'This is a manifest where there is no thumbnail property but the thumbnail can be generated from the level 0 image service.', | ||
}, | ||
{ | ||
label: 'Canvas with no thumbnail property - simple image', | ||
url: 'https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/simple_image/manifest.json', | ||
description: 'This is a manifest where there is no thumbnail property. There is a single image painted onto the canvas' | ||
}, | ||
{ | ||
label: 'Canvases with thumbnail property which is an image URL', | ||
url: 'https://iiif-commons.github.io/fixtures/examples/thumbnail/thum_prop/v2/canvas_thum_url/manifest.json', | ||
description: 'Each canvas has a thumbnail property which is a URL to an image', | ||
}, | ||
{ | ||
label: 'Canvases with thumbnail property which is an image URL with dimensions', | ||
url: 'https://iiif-commons.github.io/fixtures/examples/thumbnail/thum_prop/v2/canvas_thum_dimensions/manifest.json', | ||
description: 'Each canvas has a thumbnail property which is a URL to an image. The thumbnail property includes a type but no image service' | ||
}, | ||
{ | ||
label: 'Canvases with thumbnail property with level0 image service (Most optimised option)', | ||
url: 'https://iiif-commons.github.io/fixtures/examples/thumbnail/thum_prop/v2/canvas_thum_level0/manifest.json', | ||
description: 'This is an efficient way of advertising various sizes for a thumbnail and allows a producer to cache copies of thumbnails to make them fast to retrieve.', | ||
}, | ||
]; |
66 changes: 66 additions & 0 deletions
66
fixtures/thumbnails/Canvas with no thumbnail property - ImageService.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"@context": "http://iiif.io/api/presentation/2/context.json", | ||
"@id": "https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/image_service2/manifest.json", | ||
"@type": "sc:Manifest", | ||
"label": "No thumb property", | ||
"sequences": [ | ||
{ | ||
"@type": "sc:Sequence", | ||
"label": "Default to page order", | ||
"canvases": [ | ||
{ | ||
"@id": "https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/image_service2/canvas/1", | ||
"@type": "sc:Canvas", | ||
"label": "Image 1", | ||
"height": 4032, | ||
"width": 3024, | ||
"images": [ | ||
{ | ||
"@type": "oa:Annotation", | ||
"motivation": "sc:painting", | ||
"resource": { | ||
"@id": "https://iiif.io/api/image/2.1/example/reference/918ecd18c2592080851777620de9bcb5-fountain/full/full/0/default.jpg", | ||
"@type": "dcTypes:Image", | ||
"format": "image/jpeg", | ||
"height": 4032, | ||
"width": 3024, | ||
"service": { | ||
"@context": "http://iiif.io/api/image/2/context.json", | ||
"@id": "https://iiif.io/api/image/2.1/example/reference/918ecd18c2592080851777620de9bcb5-fountain", | ||
"profile": "http://iiif.io/api/image/2/level2.json" | ||
} | ||
}, | ||
"on": "https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/image_service2/canvas/1" | ||
} | ||
] | ||
}, | ||
{ | ||
"@id": "https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/image_service2/canvas/2", | ||
"@type": "sc:Canvas", | ||
"label": "Image 2", | ||
"height": 4032, | ||
"width": 3024, | ||
"images": [ | ||
{ | ||
"@type": "oa:Annotation", | ||
"motivation": "sc:painting", | ||
"resource": { | ||
"@id": "https://iiif.io/api/image/2.1/example/reference/918ecd18c2592080851777620de9bcb5-gottingen/full/full/0/default.jpg", | ||
"@type": "dcTypes:Image", | ||
"format": "image/jpeg", | ||
"height": 4032, | ||
"width": 3024, | ||
"service": { | ||
"@context": "http://iiif.io/api/image/2/context.json", | ||
"@id": "https://iiif.io/api/image/2.1/example/reference/918ecd18c2592080851777620de9bcb5-gottingen", | ||
"profile": "http://iiif.io/api/image/2/level2.json" | ||
} | ||
}, | ||
"on": "https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/image_service2/canvas/2" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
66 changes: 66 additions & 0 deletions
66
fixtures/thumbnails/Canvas with no thumbnail property - level0 image.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"@context": "http://iiif.io/api/presentation/2/context.json", | ||
"@id": "https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/level0/manifest.json", | ||
"@type": "sc:Manifest", | ||
"label": "No thumb property - level 0", | ||
"sequences": [ | ||
{ | ||
"@type": "sc:Sequence", | ||
"label": "Default to page order", | ||
"canvases": [ | ||
{ | ||
"@id": "https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/level0/canvas/1", | ||
"@type": "sc:Canvas", | ||
"label": "Image 1", | ||
"height": 3023, | ||
"width": 4031, | ||
"images": [ | ||
{ | ||
"@type": "oa:Annotation", | ||
"motivation": "sc:painting", | ||
"resource": { | ||
"@id": "https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/level0/tractor/full/full/0/default.jpg", | ||
"@type": "dcTypes:Image", | ||
"format": "image/jpeg", | ||
"height": 3023, | ||
"width": 4031, | ||
"service": { | ||
"@context": "http://iiif.io/api/image/2/context.json", | ||
"@id": "https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/level0/tractor", | ||
"profile": "http://iiif.io/api/image/2/level0.json" | ||
} | ||
}, | ||
"on": "https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/level0/canvas/1" | ||
} | ||
] | ||
}, | ||
{ | ||
"@id": "https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/level0/canvas/2", | ||
"@type": "sc:Canvas", | ||
"label": "Image 2", | ||
"height": 3024, | ||
"width": 4032, | ||
"images": [ | ||
{ | ||
"@type": "oa:Annotation", | ||
"motivation": "sc:painting", | ||
"resource": { | ||
"@id": "https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/level0/van/full/full/0/default.jpg", | ||
"@type": "dcTypes:Image", | ||
"format": "image/jpeg", | ||
"height": 3024, | ||
"width": 4032, | ||
"service": { | ||
"@context": "http://iiif.io/api/image/2/context.json", | ||
"@id": "https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/level0/van", | ||
"profile": "http://iiif.io/api/image/2/level0.json" | ||
} | ||
}, | ||
"on": "https://iiif-commons.github.io/fixtures/examples/thumbnail/no_thum_prop/v2/level0/canvas/2" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.