Skip to content

Commit

Permalink
local tweaked file to extract thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
funkydunc committed Jan 21, 2025
1 parent 72b9a8c commit f8a63fb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
7 changes: 6 additions & 1 deletion apps/iiif/.iiifrc-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ run:
- extract-slug-source
- delft-extract-labels
- extract-part-of-collection
- extract-thumbnail
- extract-thumbnail-local
- manifest-sqlite
- metadata-analysis
- site-collections
- delft-image-source
- typesense-manifests

config:
extract-thumbnail-local:
width: 1080
height: 1080

stores:
collective-access:
type: iiif-json
Expand Down
56 changes: 56 additions & 0 deletions apps/iiif/scripts/extract-thumbnail-local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { createThumbnailHelper } from "@iiif/helpers";
import { extract } from "iiif-hss";

extract({
id: "extract-thumbnail-local",
name: "Extract Thumbnail",
types: ["Manifest"],
invalidate: async (resource, api, config) => {
const cache = await api.caches.value;
return !cache.extractThumbnail && cache.extractThumbnail !== false;
}},
async (resource, api, config) => {
const vault = resource.vault;
const helper = createThumbnailHelper(vault);
const thumbnail = await helper.getBestThumbnailAtSize(
api.resource,
config.width
? {
width: config.width,
height: config.height || config.width,
}
: {
width: 256,
height: 256,
},
config.dereference || false
);

if (thumbnail?.best) {
return {
meta: { thumbnail: thumbnail.best },
caches: { extractThumbnail: true },
};
}
else {
const thumbnail = await helper.getBestThumbnailAtSize(
api.resource, {
width: 256,
height: 256,
},
config.dereference || false
);

if (thumbnail?.best) {
return {
meta: { thumbnail: thumbnail.best },
caches: { extractThumbnail: true },
};
}
}

return {
caches: { extractThumbnail: false },
};
},
)

0 comments on commit f8a63fb

Please sign in to comment.