Skip to content

Commit

Permalink
added thumbnail to manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardKoschicek committed Oct 4, 2023
1 parent f25aacc commit 5107ecf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
30 changes: 23 additions & 7 deletions openatlas/api/endpoints/iiif.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class IIIFSequence(Resource):
@staticmethod
def get(id_: int) -> Response:
def get(version: int, id_: int) -> Response:
img_url = f"{app.config['IIIF']['url']}{id_}"
req = requests.get(f"{img_url}/info.json")
img_api = req.json()
Expand All @@ -27,6 +27,7 @@ def build_sequence(entity: Entity, img_url: str, img_api: dict[str, Any]):
"@id": url_for(
'api.iiif_sequence',
id_=entity.id,
version=2,
_external=True),
"@type": "sc:Sequence",
"label": [{
Expand All @@ -38,7 +39,7 @@ def build_sequence(entity: Entity, img_url: str, img_api: dict[str, Any]):

class IIIFCanvas(Resource):
@staticmethod
def get(id_: int) -> Response:
def get(version: int, id_: int) -> Response:
img_url = f"{app.config['IIIF']['url']}{id_}"
req = requests.get(f"{img_url}/info.json")
img_api = req.json()
Expand All @@ -50,7 +51,8 @@ def get(id_: int) -> Response:
@staticmethod
def build_canvas(entity: Entity, img_url: str, img_api: dict[str, Any]):
return {
"@id": url_for('api.iiif_canvas', id_=entity.id, _external=True),
"@id": url_for(
'api.iiif_canvas', id_=entity.id, version=2, _external=True),
"@type": "sc:Canvas",
"label": entity.name,
"height": img_api['height'],
Expand All @@ -60,12 +62,24 @@ def build_canvas(entity: Entity, img_url: str, img_api: dict[str, Any]):
"@language": "en"},
"images": [
IIIFImage.build_image(entity.id, img_url, img_api)],
"related": ""}
"related": "",
"thumbnail": {
"@id": f'{img_url}/full/!200,200/0/default.jpg',
"@type": "dctypes:Image",
"format": "image/jpeg",
"height": 200,
"width": 200,
"service": {
"@context": "http://iiif.io/api/image/2/context.json",
"@id": img_url,
"profile": img_api['profile']},
},
}


class IIIFImage(Resource):
@staticmethod
def get(id_: int) -> Response:
def get(version: int, id_: int) -> Response:
image_url = f"{app.config['IIIF']['url']}{id_}"
req = requests.get(f"{image_url}/info.json")
image_api = req.json()
Expand All @@ -75,7 +89,8 @@ def get(id_: int) -> Response:
def build_image(id_: int, img_url: str, img_api: dict[str, Any]):
return {
"@context": "https://iiif.io/api/presentation/2/context.json",
"@id": url_for('api.iiif_image', id_=id_, _external=True),
"@id":
url_for('api.iiif_image', id_=id_, version=2, _external=True),
"@type": "oa:Annotation",
"motivation": "sc:painting",
"resource": {
Expand All @@ -88,7 +103,8 @@ def build_image(id_: int, img_url: str, img_api: dict[str, Any]):
"profile": img_api['profile']},
"height": img_api['height'],
"width": img_api['width']},
"on": url_for('api.iiif_canvas', id_=id_, _external=True)}
"on":
url_for('api.iiif_canvas', id_=id_, version=2, _external=True)}


class IIIFManifest(Resource):
Expand Down
6 changes: 3 additions & 3 deletions openatlas/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ def add_routes_v03(api: Api) -> None:
endpoint='iiif_manifest')
api.add_resource(
IIIFImage,
'/iiif_image/<int:id_>.json',
'/iiif_image/<int:version>/<int:id_>.json',
endpoint='iiif_image')
api.add_resource(
IIIFCanvas,
'/iiif_canvas/<int:id_>.json',
'/iiif_canvas/<int:version>/<int:id_>.json',
endpoint='iiif_canvas')
api.add_resource(
IIIFSequence,
'/iiif_sequence/<int:id_>.json',
'/iiif_sequence/<int:version>/<int:id_>.json',
endpoint='iiif_sequence')

0 comments on commit 5107ecf

Please sign in to comment.