diff --git a/recipes/scripts/0036-composition-from-multiple-images-method1.py b/recipes/scripts/0036-composition-from-multiple-images-method1.py
new file mode 100644
index 0000000..b77b8bb
--- /dev/null
+++ b/recipes/scripts/0036-composition-from-multiple-images-method1.py
@@ -0,0 +1,63 @@
+from iiif_prezi3 import Manifest, ResourceItem, AnnotationPage, Annotation, config
+
+config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"
+base_url = "https://iiif.io/api/cookbook/recipe/0036-composition-from-multiple-images"
+
+manifest = Manifest(
+ id=f"{base_url}/manifest.json",
+ label="Folio from Grandes Chroniques de France, ca. 1460"
+)
+canvas = manifest.make_canvas(
+ id=f"{base_url}/canvas/p1",
+ height=5412,
+ width=7216
+)
+canvas.add_label(language="none", value="f. 033v-034r [Chilpéric Ier tue Galswinthe, se remarie et est assassiné]")
+
+anno_body_a = ResourceItem(
+ id="https://iiif.io/api/image/3.0/example/reference/899da506920824588764bc12b10fc800-bnf_chateauroux/full/max/0/default.jpg",
+ type="Image",
+ format="image/jpeg",
+ height=5412,
+ width=7216
+)
+anno_body_a.make_service(
+ id="https://iiif.io/api/image/3.0/example/reference/899da506920824588764bc12b10fc800-bnf_chateauroux",
+ type="ImageService3",
+ profile="level1"
+)
+anno_page = AnnotationPage(
+ id=f"{base_url}/page/p1/1"
+)
+annotation_a = Annotation(
+ id=f"{base_url}/annotation/p0001-image",
+ motivation="painting",
+ body=anno_body_a,
+ target=canvas.id
+)
+
+anno_body_b = ResourceItem(
+ id="https://iiif.io/api/image/3.0/example/reference/899da506920824588764bc12b10fc800-bnf_chateauroux_miniature/full/max/0/default.jpg",
+ type="Image",
+ format="image/jpeg",
+ width=2138,
+ height=2414
+)
+anno_body_b.add_label(language="fr", value="Miniature [Chilpéric Ier tue Galswinthe, se remarie et est assassiné]")
+anno_body_b.make_service(
+ id="https://iiif.io/api/image/3.0/example/reference/899da506920824588764bc12b10fc800-bnf_chateauroux_miniature",
+ type="ImageService3",
+ profile="level1"
+)
+annotation_b = Annotation(
+ id=f"{base_url}/annotation/p0002-image",
+ motivation="painting",
+ body=anno_body_b,
+ target=f"{canvas.id}#xywh=3949,994,1091,1232"
+)
+
+anno_page.add_item(annotation_a)
+anno_page.add_item(annotation_b)
+canvas.add_item(anno_page)
+
+print(manifest.json(indent=2))
\ No newline at end of file
diff --git a/search/search_index.json b/search/search_index.json
index 87047e8..44595d0 100644
--- a/search/search_index.json
+++ b/search/search_index.json
@@ -1 +1 @@
-{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"iiif-prezi3","text":"IIIF Presentation API 3 Python Library
"},{"location":"#installation","title":"Installation","text":""},{"location":"#pypi","title":"PyPI","text":"The easiest way to install the iiif-prezi3
library is directly from PyPI:
pip install iiif-prezi3\n
"},{"location":"#manual-installation","title":"Manual installation","text":"Alternatively, you can clone the repository and run setup.py
locally:
git clone https://github.com/iiif-prezi/iiif-prezi3.git\n
or git clone git@github.com:iiif-prezi/iiif-prezi3.git\n
followed by: cd iiif-prezi3\npython setup.py install\n
"},{"location":"#basic-usage","title":"Basic Usage","text":"You can now import the library or individual classes from within Python and start creating your IIIF Presentation 3 objects:
"},{"location":"#directly-creating-a-manifest","title":"Directly creating a Manifest","text":">>> from iiif_prezi3 import Manifest\n>>> m = Manifest(id=\"https://example.com/iiif/manifest.json\", label={\"en\":[\"Example Manifest\"]})\n>>> print(m.json(indent=2))\n{\n \"@context\": \"http://iiif.io/api/presentation/3/context.json\",\n \"id\": \"https://example.com/iiif/manifest.json\",\n \"type\": \"Manifest\",\n \"label\": {\n \"en\": [\n \"Example Manifest\"\n ]\n }\n}\n
"},{"location":"#importing-an-existing-iiif-manifest","title":"Importing an existing IIIF Manifest","text":"If you have an existing IIIF Presentation v3 Manifest, you can load it via the built-in json
module and create the objects:
>>> from iiif_prezi3 import Manifest\n>>> import json\n>>> manifest_json = json.load(open(\"example.json\"))\n>>> m = Manifest(**manifest_json)\n>>> print(m.json(indent=2))\n{\n \"@context\": \"http://iiif.io/api/presentation/3/context.json\",\n \"id\": \"https://iiif.io/api/cookbook/recipe/0003-mvm-video/manifest.json\",\n \"type\": \"Manifest\",\n \"label\": {\n \"en\": [\n \"Video Example 3\"\n ]\n },\n \"items\": [\n {\n \"id\": \"https://iiif.io/api/cookbook/recipe/0003-mvm-video/canvas\",\n \"type\": \"Canvas\",\n \"height\": 360,\n \"width\": 640,\n \"duration\": 572.034,\n \"items\": [\n {\n \"id\": \"https://iiif.io/api/cookbook/recipe/0003-mvm-video/canvas/page\",\n \"type\": \"AnnotationPage\",\n \"items\": [\n {\n \"id\": \"https://iiif.io/api/cookbook/recipe/0003-mvm-video/canvas/page/annotation\",\n \"type\": \"Annotation\",\n \"motivation\": \"painting\",\n \"body\": {\n \"id\": \"https://fixtures.iiif.io/video/indiana/lunchroom_manners/high/lunchroom_manners_1024kb.mp4\",\n \"type\": \"Video\",\n \"height\": 360,\n \"width\": 480,\n \"duration\": 572.034,\n \"format\": \"video/mp4\"\n },\n \"target\": \"https://iiif.io/api/cookbook/recipe/0003-mvm-video/canvas\"\n }\n ]\n }\n ]\n }\n ]\n}\n
"},{"location":"#extensions","title":"Extensions","text":"iiif-prezi3
includes the capability to load extensions to the IIIF Presentation schema (e.g navPlace) and modify the library's Python classes to include extra properties, validation, helper methods, etc.
Published extensions from the IIIF Registry of Extensions are included with the package, and can be loaded using the iiif_prezi3.load_bundled_extensions()
method.
Called without argument, this method will load all bundled extensions listed in the iiif_prezi3/config/extensions.json file. If you wish to only load selected extensions from those available bundled with the library, you can pass either the path to a JSON file, or a list of extension names as an argument to the function:
>>> import iiif_prezi3\n>>> iiif_prezi3.load_bundled_extensions(extensions=\"/path/to/chosen_extensions.json\")\n
>>> import iiif_prezi3\n>>> iiif_prezi3.load_bundled_extensions(extensions=['example_extension'])\n
Extensions work in much the same way as helper methods, and are monkeypatched into the relevant objects in the iiif_prezi3.skeleton
class, from which everything is loaded. For a simple example, please see the extensions/example_extension.py
file, and the documentation on writing a helper method.
"},{"location":"#local-development","title":"Local Development","text":"For developing iiif-prezi3
locally, clone the repo and then install it and the development dependencies using pip's \"editable mode\":
git clone git@github.com:iiif-prezi/iiif-prezi3.git\ncd iiif-prezi3\npip install -e .[dev]\n
"},{"location":"#running-tests","title":"Running Tests","text":"Tests (including linting) can be run using tox. First, install tox with pip install tox
, then type tox
.
"},{"location":"#versioning","title":"Versioning","text":"iiif-prezi3
broadly follows Semantic Versioning. Patch releases are used for bug fixes, minor releases add new functionality and maintain backwards compatibility, and major versions contain breaking changes to the public API of the library. Links to the changes between individual versions can be found on the releases page.
"},{"location":"#get-involved","title":"Get Involved","text":"The iiif-prezi3
maintainers welcome contributions from the community - issues, pull requests, use cases, etc. We have a guideline document for contributions and a channel #iiif-prezi3
on the IIIF Slack workspace, which can be joined from the IIIF website's Get Involved page.
"},{"location":"code/","title":"Code reference","text":""},{"location":"code/#iiif_prezi3.AddImage","title":"AddImage
","text":"Source code in iiif_prezi3/helpers/add_image.py
class AddImage:\n\n def add_image(self, image_url, anno_id=None, anno_page_id=None, **kwargs):\n \"\"\"Adds an image to an existing canvas.\n\n Args:\n image_url (str): An HTTP URL which points to the image.\n anno_id (str): An HTTP URL for the annotation to which the image will be attached.\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n\n Returns:\n anno_page (AnnotationPage): the AnnotationPage with an Annotation and ResourceItem attached.\n \"\"\"\n body = ResourceItem(id=image_url, type='Image', **kwargs)\n annotation = Annotation(id=anno_id, body=body, target=self.id, motivation='painting', type='Annotation')\n anno_page = AnnotationPage(id=anno_page_id, type='AnnotationPage', items=[annotation])\n if not self.items:\n self.items = list()\n self.items.append(anno_page)\n return anno_page\n
"},{"location":"code/#iiif_prezi3.AddImage.add_image","title":"add_image(image_url, anno_id=None, anno_page_id=None, **kwargs)
","text":"Adds an image to an existing canvas.
Parameters:
Name Type Description Default image_url
str
An HTTP URL which points to the image.
required anno_id
str
An HTTP URL for the annotation to which the image will be attached.
None
anno_page_id
str
An HTTP URL for the annotation page to which the annotation will be attached.
None
Returns:
Name Type Description anno_page
AnnotationPage
the AnnotationPage with an Annotation and ResourceItem attached.
Source code in iiif_prezi3/helpers/add_image.py
def add_image(self, image_url, anno_id=None, anno_page_id=None, **kwargs):\n \"\"\"Adds an image to an existing canvas.\n\n Args:\n image_url (str): An HTTP URL which points to the image.\n anno_id (str): An HTTP URL for the annotation to which the image will be attached.\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n\n Returns:\n anno_page (AnnotationPage): the AnnotationPage with an Annotation and ResourceItem attached.\n \"\"\"\n body = ResourceItem(id=image_url, type='Image', **kwargs)\n annotation = Annotation(id=anno_id, body=body, target=self.id, motivation='painting', type='Annotation')\n anno_page = AnnotationPage(id=anno_page_id, type='AnnotationPage', items=[annotation])\n if not self.items:\n self.items = list()\n self.items.append(anno_page)\n return anno_page\n
"},{"location":"code/#iiif_prezi3.AddItem","title":"AddItem
","text":"Source code in iiif_prezi3/helpers/add_item.py
class AddItem:\n def add_item(self, item):\n \"\"\"Add a IIIF Prezi3 object to the items list, creating it if it doesn't exist.\n\n Args:\n item (Union[Collection, Manifest, Canvas, AnnotationPage, Annotation, Range, Reference, SpecificResource, Item])): The object to be added\n \"\"\"\n if not self.items:\n self.items = []\n\n # If the item is a Manifest, and the target is a Collection, convert it to a reference\n if isinstance(item, Manifest) and isinstance(self, Collection):\n item = item.to_reference()\n\n self.items.append(item)\n self.items = self.items # Force Pydantic to validate?\n
"},{"location":"code/#iiif_prezi3.AddItem.add_item","title":"add_item(item)
","text":"Add a IIIF Prezi3 object to the items list, creating it if it doesn't exist.
Parameters:
Name Type Description Default item
Union[Collection, Manifest, Canvas, AnnotationPage, Annotation, Range, Reference, SpecificResource, Item]
The object to be added
required Source code in iiif_prezi3/helpers/add_item.py
def add_item(self, item):\n \"\"\"Add a IIIF Prezi3 object to the items list, creating it if it doesn't exist.\n\n Args:\n item (Union[Collection, Manifest, Canvas, AnnotationPage, Annotation, Range, Reference, SpecificResource, Item])): The object to be added\n \"\"\"\n if not self.items:\n self.items = []\n\n # If the item is a Manifest, and the target is a Collection, convert it to a reference\n if isinstance(item, Manifest) and isinstance(self, Collection):\n item = item.to_reference()\n\n self.items.append(item)\n self.items = self.items # Force Pydantic to validate?\n
"},{"location":"code/#iiif_prezi3.AddItemByReference","title":"AddItemByReference
","text":"Source code in iiif_prezi3/helpers/add_item.py
class AddItemByReference:\n def add_item_by_reference(self, item):\n \"\"\"Add a IIIF Prezi3 object by reference to the items list, creating it if it doesn't exist.\n\n Args:\n item (Union[Manifest, AnnotationPage, Collection, AnnotationCollection, Canvas])): The object to be added\n \"\"\"\n if not self.items:\n self.items = []\n\n item = item.to_reference()\n\n self.items.append(item)\n self.items = self.items # Force Pydantic to validate?\n
"},{"location":"code/#iiif_prezi3.AddItemByReference.add_item_by_reference","title":"add_item_by_reference(item)
","text":"Add a IIIF Prezi3 object by reference to the items list, creating it if it doesn't exist.
Parameters:
Name Type Description Default item
Union[Manifest, AnnotationPage, Collection, AnnotationCollection, Canvas]
The object to be added
required Source code in iiif_prezi3/helpers/add_item.py
def add_item_by_reference(self, item):\n \"\"\"Add a IIIF Prezi3 object by reference to the items list, creating it if it doesn't exist.\n\n Args:\n item (Union[Manifest, AnnotationPage, Collection, AnnotationCollection, Canvas])): The object to be added\n \"\"\"\n if not self.items:\n self.items = []\n\n item = item.to_reference()\n\n self.items.append(item)\n self.items = self.items # Force Pydantic to validate?\n
"},{"location":"code/#iiif_prezi3.AddLabel","title":"AddLabel
","text":"Source code in iiif_prezi3/helpers/add_label.py
class AddLabel:\n\n def add_label(self, value, language=None):\n \"\"\"Adds a label to an existing resource.\n\n Args:\n value (Union[str, list]): The label or labels to be added\n language (str): An optional language for the labels. If not provided it will default using the AutoLang configuration.\n \"\"\"\n if not self.label:\n if not language:\n self.label = value\n else:\n if type(value) != list:\n value = [value]\n self.label = {language: value}\n else:\n # fetch as dict not LngString\n curr = self.label\n if not language:\n language = configs['helpers.auto_fields.AutoLang'].auto_lang\n if language in curr:\n curr[language].append(value)\n else:\n if type(value) != list:\n value = [value]\n curr[language] = value\n self.label = curr\n
"},{"location":"code/#iiif_prezi3.AddLabel.add_label","title":"add_label(value, language=None)
","text":"Adds a label to an existing resource.
Parameters:
Name Type Description Default value
Union[str, list]
The label or labels to be added
required language
str
An optional language for the labels. If not provided it will default using the AutoLang configuration.
None
Source code in iiif_prezi3/helpers/add_label.py
def add_label(self, value, language=None):\n \"\"\"Adds a label to an existing resource.\n\n Args:\n value (Union[str, list]): The label or labels to be added\n language (str): An optional language for the labels. If not provided it will default using the AutoLang configuration.\n \"\"\"\n if not self.label:\n if not language:\n self.label = value\n else:\n if type(value) != list:\n value = [value]\n self.label = {language: value}\n else:\n # fetch as dict not LngString\n curr = self.label\n if not language:\n language = configs['helpers.auto_fields.AutoLang'].auto_lang\n if language in curr:\n curr[language].append(value)\n else:\n if type(value) != list:\n value = [value]\n curr[language] = value\n self.label = curr\n
"},{"location":"code/#iiif_prezi3.AddService","title":"AddService
","text":"Source code in iiif_prezi3/helpers/add_service.py
class AddService:\n def add_service(self, service):\n \"\"\"Add a IIIF Prezi service to the service list.\n\n Args:\n service (ServiceItem,ServiceItem1,Service): A iiif-prezi ServiceItem.\n \"\"\"\n if isinstance(service, (ServiceItem, ServiceItem1)):\n if not self.service:\n self.service = []\n self.service.append(service)\n self.service = self.service\n else:\n raise TypeError(\"Not a valid IIIF service.\")\n
"},{"location":"code/#iiif_prezi3.AddService.add_service","title":"add_service(service)
","text":"Add a IIIF Prezi service to the service list.
Parameters:
Name Type Description Default service
(ServiceItem, ServiceItem1, Service)
A iiif-prezi ServiceItem.
required Source code in iiif_prezi3/helpers/add_service.py
def add_service(self, service):\n \"\"\"Add a IIIF Prezi service to the service list.\n\n Args:\n service (ServiceItem,ServiceItem1,Service): A iiif-prezi ServiceItem.\n \"\"\"\n if isinstance(service, (ServiceItem, ServiceItem1)):\n if not self.service:\n self.service = []\n self.service.append(service)\n self.service = self.service\n else:\n raise TypeError(\"Not a valid IIIF service.\")\n
"},{"location":"code/#iiif_prezi3.AddThumbnail","title":"AddThumbnail
","text":"Source code in iiif_prezi3/helpers/add_thumbnail.py
class AddThumbnail:\n def add_thumbnail(self, image_url, **kwargs):\n \"\"\"Adds a thumbnail to an existing canvas.\n\n Args:\n image_url (str): An HTTP URL which points to the thumbnail.\n **kwargs (): see ResourceItem.\n\n Returns:\n new_thumbnail (ResourceItem): the newly-created thumbnail.\n \"\"\"\n new_thumbnail = ResourceItem(id=image_url, type='Image', **kwargs)\n if not self.thumbnail:\n self.thumbnail = list()\n self.thumbnail.append(new_thumbnail)\n return new_thumbnail\n
"},{"location":"code/#iiif_prezi3.AddThumbnail.add_thumbnail","title":"add_thumbnail(image_url, **kwargs)
","text":"Adds a thumbnail to an existing canvas.
Parameters:
Name Type Description Default image_url
str
An HTTP URL which points to the thumbnail.
required **kwargs
see ResourceItem.
{}
Returns:
Name Type Description new_thumbnail
ResourceItem
the newly-created thumbnail.
Source code in iiif_prezi3/helpers/add_thumbnail.py
def add_thumbnail(self, image_url, **kwargs):\n \"\"\"Adds a thumbnail to an existing canvas.\n\n Args:\n image_url (str): An HTTP URL which points to the thumbnail.\n **kwargs (): see ResourceItem.\n\n Returns:\n new_thumbnail (ResourceItem): the newly-created thumbnail.\n \"\"\"\n new_thumbnail = ResourceItem(id=image_url, type='Image', **kwargs)\n if not self.thumbnail:\n self.thumbnail = list()\n self.thumbnail.append(new_thumbnail)\n return new_thumbnail\n
"},{"location":"code/#iiif_prezi3.AnnotationHelpers","title":"AnnotationHelpers
","text":"Source code in iiif_prezi3/helpers/annotation_helpers.py
class AnnotationHelpers:\n\n def add_annotation(self, annotation, anno_page_id=None):\n \"\"\"Adds the annotation object to the (AnnotationPage object in the) annotations property.\n\n Creates an AnnotationPage object if it doesn't exist.\n\n Args:\n annotation (Annotation): the Annotation to add\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n\n Returns:\n annotation (Annotation): the Annotation attached to the AnnotationPage.\n\n \"\"\"\n if not self.annotations:\n self.annotations = list()\n\n if len(self.annotations) == 0:\n # add empty AnnotationPage\n anno_page = AnnotationPage(id=anno_page_id, items=[])\n self.annotations.append(anno_page)\n else:\n anno_page = self.annotations[0]\n\n anno_page.items.append(annotation)\n\n return annotation\n\n def make_annotation(self, anno_page_id=None, **kwargs):\n \"\"\"Creates an annotation object and adds it to the annotations property using .add_annotation().\n\n Args:\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n **kwargs (): see Annotation.\n \"\"\"\n annotation = Annotation(**kwargs)\n self.add_annotation(annotation, anno_page_id=anno_page_id)\n return annotation\n
"},{"location":"code/#iiif_prezi3.AnnotationHelpers.add_annotation","title":"add_annotation(annotation, anno_page_id=None)
","text":"Adds the annotation object to the (AnnotationPage object in the) annotations property.
Creates an AnnotationPage object if it doesn't exist.
Parameters:
Name Type Description Default annotation
Annotation
the Annotation to add
required anno_page_id
str
An HTTP URL for the annotation page to which the annotation will be attached.
None
Returns:
Name Type Description annotation
Annotation
the Annotation attached to the AnnotationPage.
Source code in iiif_prezi3/helpers/annotation_helpers.py
def add_annotation(self, annotation, anno_page_id=None):\n \"\"\"Adds the annotation object to the (AnnotationPage object in the) annotations property.\n\n Creates an AnnotationPage object if it doesn't exist.\n\n Args:\n annotation (Annotation): the Annotation to add\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n\n Returns:\n annotation (Annotation): the Annotation attached to the AnnotationPage.\n\n \"\"\"\n if not self.annotations:\n self.annotations = list()\n\n if len(self.annotations) == 0:\n # add empty AnnotationPage\n anno_page = AnnotationPage(id=anno_page_id, items=[])\n self.annotations.append(anno_page)\n else:\n anno_page = self.annotations[0]\n\n anno_page.items.append(annotation)\n\n return annotation\n
"},{"location":"code/#iiif_prezi3.AnnotationHelpers.make_annotation","title":"make_annotation(anno_page_id=None, **kwargs)
","text":"Creates an annotation object and adds it to the annotations property using .add_annotation().
Parameters:
Name Type Description Default anno_page_id
str
An HTTP URL for the annotation page to which the annotation will be attached.
None
**kwargs
see Annotation.
{}
Source code in iiif_prezi3/helpers/annotation_helpers.py
def make_annotation(self, anno_page_id=None, **kwargs):\n \"\"\"Creates an annotation object and adds it to the annotations property using .add_annotation().\n\n Args:\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n **kwargs (): see Annotation.\n \"\"\"\n annotation = Annotation(**kwargs)\n self.add_annotation(annotation, anno_page_id=anno_page_id)\n return annotation\n
"},{"location":"code/#iiif_prezi3.CreateCanvasFromIIIF","title":"CreateCanvasFromIIIF
","text":"Source code in iiif_prezi3/helpers/create_canvas_from_iiif.py
class CreateCanvasFromIIIF:\n # should probably be added to canvas helpers\n\n def create_canvas_from_iiif(self, url, anno_id=None, anno_page_id=None, **kwargs):\n \"\"\"Create a canvas from a IIIF Image URL.\n\n Creates a canvas from a IIIF Image service passing any kwargs to the Canvas.\n\n Args:\n url (str): An HTTP URL at which at a IIIF Image is available.\n anno_id (str): An HTTP URL for the annotation to which the image will be attached.\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n **kwargs (): see Canvas\n\n Returns:\n canvas (Canvas): the Canvas created from the IIIF Image.\n\n \"\"\"\n canvas = Canvas(**kwargs)\n\n body = ResourceItem(id=\"http://example.com\", type=\"Image\")\n infoJson = body.set_hwd_from_iiif(url)\n\n # Will need to handle IIIF 2...\n if 'type' not in infoJson:\n # Assume v2\n\n # V2 profile contains profile URI plus extra features\n profile = ''\n for item in infoJson['profile']:\n if isinstance(item, str):\n profile = item\n break\n\n service = ServiceItem1(id=infoJson['@id'], profile=profile, type=\"ImageService2\")\n body.service = [service]\n body.id = f'{infoJson[\"@id\"]}/full/full/0/default.jpg'\n body.format = \"image/jpeg\"\n else:\n service = ServiceItem(id=infoJson['id'], profile=infoJson['profile'], type=infoJson['type'])\n body.service = [service]\n body.id = f'{infoJson[\"id\"]}/full/max/0/default.jpg'\n body.format = \"image/jpeg\"\n\n annotation = Annotation(id=anno_id, motivation='painting', body=body, target=canvas.id)\n\n annotationPage = AnnotationPage(id=anno_page_id)\n annotationPage.add_item(annotation)\n\n canvas.add_item(annotationPage)\n canvas.set_hwd(infoJson['height'], infoJson['width'])\n\n return canvas\n\n def make_canvas_from_iiif(self, url, **kwargs):\n canvas = self.create_canvas_from_iiif(url, **kwargs)\n\n self.add_item(canvas)\n return canvas\n
"},{"location":"code/#iiif_prezi3.CreateCanvasFromIIIF.create_canvas_from_iiif","title":"create_canvas_from_iiif(url, anno_id=None, anno_page_id=None, **kwargs)
","text":"Create a canvas from a IIIF Image URL.
Creates a canvas from a IIIF Image service passing any kwargs to the Canvas.
Parameters:
Name Type Description Default url
str
An HTTP URL at which at a IIIF Image is available.
required anno_id
str
An HTTP URL for the annotation to which the image will be attached.
None
anno_page_id
str
An HTTP URL for the annotation page to which the annotation will be attached.
None
**kwargs
see Canvas
{}
Returns:
Name Type Description canvas
Canvas
the Canvas created from the IIIF Image.
Source code in iiif_prezi3/helpers/create_canvas_from_iiif.py
def create_canvas_from_iiif(self, url, anno_id=None, anno_page_id=None, **kwargs):\n \"\"\"Create a canvas from a IIIF Image URL.\n\n Creates a canvas from a IIIF Image service passing any kwargs to the Canvas.\n\n Args:\n url (str): An HTTP URL at which at a IIIF Image is available.\n anno_id (str): An HTTP URL for the annotation to which the image will be attached.\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n **kwargs (): see Canvas\n\n Returns:\n canvas (Canvas): the Canvas created from the IIIF Image.\n\n \"\"\"\n canvas = Canvas(**kwargs)\n\n body = ResourceItem(id=\"http://example.com\", type=\"Image\")\n infoJson = body.set_hwd_from_iiif(url)\n\n # Will need to handle IIIF 2...\n if 'type' not in infoJson:\n # Assume v2\n\n # V2 profile contains profile URI plus extra features\n profile = ''\n for item in infoJson['profile']:\n if isinstance(item, str):\n profile = item\n break\n\n service = ServiceItem1(id=infoJson['@id'], profile=profile, type=\"ImageService2\")\n body.service = [service]\n body.id = f'{infoJson[\"@id\"]}/full/full/0/default.jpg'\n body.format = \"image/jpeg\"\n else:\n service = ServiceItem(id=infoJson['id'], profile=infoJson['profile'], type=infoJson['type'])\n body.service = [service]\n body.id = f'{infoJson[\"id\"]}/full/max/0/default.jpg'\n body.format = \"image/jpeg\"\n\n annotation = Annotation(id=anno_id, motivation='painting', body=body, target=canvas.id)\n\n annotationPage = AnnotationPage(id=anno_page_id)\n annotationPage.add_item(annotation)\n\n canvas.add_item(annotationPage)\n canvas.set_hwd(infoJson['height'], infoJson['width'])\n\n return canvas\n
"},{"location":"code/#iiif_prezi3.MakeCanvas","title":"MakeCanvas
","text":"Source code in iiif_prezi3/helpers/make_canvas.py
class MakeCanvas:\n\n def make_canvas(self, **kwargs):\n \"\"\"Add a Canvas to a Manifest.\n\n Creates a new Canvas, appends it to the\n calling Manifest items and returns the newly created Canvas.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n canvas = Canvas(**kwargs)\n self.add_item(canvas)\n return canvas\n
"},{"location":"code/#iiif_prezi3.MakeCanvas.make_canvas","title":"make_canvas(**kwargs)
","text":"Add a Canvas to a Manifest.
Creates a new Canvas, appends it to the calling Manifest items and returns the newly created Canvas. Accepts keyword arguments to customize the resulting instance.
Source code in iiif_prezi3/helpers/make_canvas.py
def make_canvas(self, **kwargs):\n \"\"\"Add a Canvas to a Manifest.\n\n Creates a new Canvas, appends it to the\n calling Manifest items and returns the newly created Canvas.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n canvas = Canvas(**kwargs)\n self.add_item(canvas)\n return canvas\n
"},{"location":"code/#iiif_prezi3.MakeCollection","title":"MakeCollection
","text":"Source code in iiif_prezi3/helpers/make_collection.py
class MakeCollection:\n\n def make_collection(self, **kwargs):\n \"\"\"Create a Collection.\n\n Creates a new collection, adds it to the calling Collection `items`\n and returns the newly created object. Accepts keyword arguments to\n customize the resulting instance.\n \"\"\"\n child_collection = Collection(**kwargs)\n self.add_item(child_collection)\n return child_collection\n
"},{"location":"code/#iiif_prezi3.MakeCollection.make_collection","title":"make_collection(**kwargs)
","text":"Create a Collection.
Creates a new collection, adds it to the calling Collection items
and returns the newly created object. Accepts keyword arguments to customize the resulting instance.
Source code in iiif_prezi3/helpers/make_collection.py
def make_collection(self, **kwargs):\n \"\"\"Create a Collection.\n\n Creates a new collection, adds it to the calling Collection `items`\n and returns the newly created object. Accepts keyword arguments to\n customize the resulting instance.\n \"\"\"\n child_collection = Collection(**kwargs)\n self.add_item(child_collection)\n return child_collection\n
"},{"location":"code/#iiif_prezi3.MakeManifest","title":"MakeManifest
","text":"Source code in iiif_prezi3/helpers/make_manifest.py
class MakeManifest:\n\n def make_manifest(self, **kwargs):\n \"\"\"Add a Manifest to a Collection.\n\n Creates a new Manifest, adds a Reference to it to the\n calling Collection items and returns the newly created Manifest.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n manifest = Manifest(**kwargs)\n self.add_item(manifest)\n return manifest\n
"},{"location":"code/#iiif_prezi3.MakeManifest.make_manifest","title":"make_manifest(**kwargs)
","text":"Add a Manifest to a Collection.
Creates a new Manifest, adds a Reference to it to the calling Collection items and returns the newly created Manifest. Accepts keyword arguments to customize the resulting instance.
Source code in iiif_prezi3/helpers/make_manifest.py
def make_manifest(self, **kwargs):\n \"\"\"Add a Manifest to a Collection.\n\n Creates a new Manifest, adds a Reference to it to the\n calling Collection items and returns the newly created Manifest.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n manifest = Manifest(**kwargs)\n self.add_item(manifest)\n return manifest\n
"},{"location":"code/#iiif_prezi3.MakeRange","title":"MakeRange
","text":"Source code in iiif_prezi3/helpers/make_range.py
class MakeRange:\n\n def make_range(self, **kwargs):\n \"\"\"Create a Range and add it to the calling Collection or Range.\n\n Creates a new Range, adds it to the calling object and returns the newly created Range.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n range = Range(**kwargs)\n if type(self) == Manifest:\n if self.structures:\n self.structures.append(range)\n else:\n self.structures = [range]\n elif type(self) == Range:\n self.add_item(range)\n return range\n
"},{"location":"code/#iiif_prezi3.MakeRange.make_range","title":"make_range(**kwargs)
","text":"Create a Range and add it to the calling Collection or Range.
Creates a new Range, adds it to the calling object and returns the newly created Range. Accepts keyword arguments to customize the resulting instance.
Source code in iiif_prezi3/helpers/make_range.py
def make_range(self, **kwargs):\n \"\"\"Create a Range and add it to the calling Collection or Range.\n\n Creates a new Range, adds it to the calling object and returns the newly created Range.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n range = Range(**kwargs)\n if type(self) == Manifest:\n if self.structures:\n self.structures.append(range)\n else:\n self.structures = [range]\n elif type(self) == Range:\n self.add_item(range)\n return range\n
"},{"location":"code/#iiif_prezi3.MakeService","title":"MakeService
","text":"Source code in iiif_prezi3/helpers/make_service.py
class MakeService:\n def make_service(self, id, type, version=3, **kwargs):\n \"\"\"Make a IIIF Prezi service of the desired IIIF API version and adds it to the service list.\n\n Args:\n id (AnyUrl): The id of the service.\n type (str): The type of the service.\n version (int): The API version of the service. Defaults to 3.\n **kwargs (): Arbitrary keyword arguments.\n\n Raises:\n ValueError: If an invalid IIIF API version is provided.\n\n Returns:\n service (Union[ServiceItem, ServiceItem1]): A service instance of the selected version.\n \"\"\"\n serviceversions = {\n 2: ServiceItem1,\n 3: ServiceItem\n }\n if version not in serviceversions:\n raise ValueError(f\"Version: {version} is not a valid IIIF API service version.\")\n service = serviceversions[version](id=id, type=type, **kwargs)\n self.add_service(service)\n return service\n
"},{"location":"code/#iiif_prezi3.MakeService.make_service","title":"make_service(id, type, version=3, **kwargs)
","text":"Make a IIIF Prezi service of the desired IIIF API version and adds it to the service list.
Parameters:
Name Type Description Default id
AnyUrl
The id of the service.
required type
str
The type of the service.
required version
int
The API version of the service. Defaults to 3.
3
**kwargs
Arbitrary keyword arguments.
{}
Raises:
Type Description ValueError
If an invalid IIIF API version is provided.
Returns:
Name Type Description service
Union[ServiceItem, ServiceItem1]
A service instance of the selected version.
Source code in iiif_prezi3/helpers/make_service.py
def make_service(self, id, type, version=3, **kwargs):\n \"\"\"Make a IIIF Prezi service of the desired IIIF API version and adds it to the service list.\n\n Args:\n id (AnyUrl): The id of the service.\n type (str): The type of the service.\n version (int): The API version of the service. Defaults to 3.\n **kwargs (): Arbitrary keyword arguments.\n\n Raises:\n ValueError: If an invalid IIIF API version is provided.\n\n Returns:\n service (Union[ServiceItem, ServiceItem1]): A service instance of the selected version.\n \"\"\"\n serviceversions = {\n 2: ServiceItem1,\n 3: ServiceItem\n }\n if version not in serviceversions:\n raise ValueError(f\"Version: {version} is not a valid IIIF API service version.\")\n service = serviceversions[version](id=id, type=type, **kwargs)\n self.add_service(service)\n return service\n
"},{"location":"code/#iiif_prezi3.SetHeightWidthDurationFileHelper","title":"SetHeightWidthDurationFileHelper
","text":"Source code in iiif_prezi3/helpers/set_hwd_from_file.py
class SetHeightWidthDurationFileHelper:\n def set_hwd_from_file(self, file_path_or_object):\n \"\"\"Introspect a file and set the height, width, and duration properties.\n\n Args:\n file_path_or_object (Union[str, fp]): the file path or file object to introspect\n \"\"\"\n if isinstance(file_path_or_object, str) or isinstance(file_path_or_object, os.PathLike):\n filetype, _ = mimetypes.guess_type(file_path_or_object)\n if not filetype.startswith(\"image/\"):\n raise NotImplementedError\n\n tmp_image = Image.open(file_path_or_object)\n w, h = tmp_image.size\n self.set_hwd(h, w, None)\n tmp_image.close()\n
"},{"location":"code/#iiif_prezi3.SetHeightWidthDurationFileHelper.set_hwd_from_file","title":"set_hwd_from_file(file_path_or_object)
","text":"Introspect a file and set the height, width, and duration properties.
Parameters:
Name Type Description Default file_path_or_object
Union[str, fp]
the file path or file object to introspect
required Source code in iiif_prezi3/helpers/set_hwd_from_file.py
def set_hwd_from_file(self, file_path_or_object):\n \"\"\"Introspect a file and set the height, width, and duration properties.\n\n Args:\n file_path_or_object (Union[str, fp]): the file path or file object to introspect\n \"\"\"\n if isinstance(file_path_or_object, str) or isinstance(file_path_or_object, os.PathLike):\n filetype, _ = mimetypes.guess_type(file_path_or_object)\n if not filetype.startswith(\"image/\"):\n raise NotImplementedError\n\n tmp_image = Image.open(file_path_or_object)\n w, h = tmp_image.size\n self.set_hwd(h, w, None)\n tmp_image.close()\n
"},{"location":"code/#iiif_prezi3.SetHwd","title":"SetHwd
","text":"Source code in iiif_prezi3/helpers/set_hwd.py
class SetHwd:\n def set_hwd(self, height=None, width=None, duration=None):\n \"\"\"Set the height, width, and duration properties allowing nulls.\n\n Args:\n height (int): The height of the resource or the canvas\n width (int): The width of the resource or the canvas\n duration (float): The duration of the resource\n \"\"\"\n if not (duration or height or width):\n raise TypeError(\"At least one of height, width, or duration must be set\")\n if height and not width:\n raise TypeError(\"width must be set if height is set\")\n if width and not height:\n raise TypeError(\"height must be set if width is set\")\n self.height = height\n self.width = width\n self.duration = duration\n
"},{"location":"code/#iiif_prezi3.SetHwd.set_hwd","title":"set_hwd(height=None, width=None, duration=None)
","text":"Set the height, width, and duration properties allowing nulls.
Parameters:
Name Type Description Default height
int
The height of the resource or the canvas
None
width
int
The width of the resource or the canvas
None
duration
float
The duration of the resource
None
Source code in iiif_prezi3/helpers/set_hwd.py
def set_hwd(self, height=None, width=None, duration=None):\n \"\"\"Set the height, width, and duration properties allowing nulls.\n\n Args:\n height (int): The height of the resource or the canvas\n width (int): The width of the resource or the canvas\n duration (float): The duration of the resource\n \"\"\"\n if not (duration or height or width):\n raise TypeError(\"At least one of height, width, or duration must be set\")\n if height and not width:\n raise TypeError(\"width must be set if height is set\")\n if width and not height:\n raise TypeError(\"height must be set if width is set\")\n self.height = height\n self.width = width\n self.duration = duration\n
"},{"location":"code/#iiif_prezi3.SetHwdFromIIIF","title":"SetHwdFromIIIF
","text":"Source code in iiif_prezi3/helpers/set_hwd_from_iiif.py
class SetHwdFromIIIF:\n # should probably be added to canvas helpers\n\n def set_hwd_from_iiif(self, url):\n \"\"\"Set height and width on a Canvas object.\n\n Requests IIIF Image information remotely for an\n image resource and sets resulting height and width.\n This method will return the info.json\n\n Args:\n url (str): An HTTP URL for the IIIF image endpoint.\n \"\"\"\n # resource url may or may not end with info.json;\n # add if not present\n if not url.endswith(\"info.json\"):\n url = f\"{ url.rstrip('/') }/info.json\"\n\n response = requests.get(url)\n # if response is not 200, raise exception\n if response.status_code != requests.codes.ok:\n response.raise_for_status()\n # if response is not valid json, request will raise\n # requests.exceptions.JSONDecodeError\n # \u2014\u00a0handle or document and let calling code handle?\n resource_info = response.json()\n self.set_hwd(resource_info.get(\"height\"), resource_info.get(\"width\"))\n\n return resource_info\n
"},{"location":"code/#iiif_prezi3.SetHwdFromIIIF.set_hwd_from_iiif","title":"set_hwd_from_iiif(url)
","text":"Set height and width on a Canvas object.
Requests IIIF Image information remotely for an image resource and sets resulting height and width. This method will return the info.json
Parameters:
Name Type Description Default url
str
An HTTP URL for the IIIF image endpoint.
required Source code in iiif_prezi3/helpers/set_hwd_from_iiif.py
def set_hwd_from_iiif(self, url):\n \"\"\"Set height and width on a Canvas object.\n\n Requests IIIF Image information remotely for an\n image resource and sets resulting height and width.\n This method will return the info.json\n\n Args:\n url (str): An HTTP URL for the IIIF image endpoint.\n \"\"\"\n # resource url may or may not end with info.json;\n # add if not present\n if not url.endswith(\"info.json\"):\n url = f\"{ url.rstrip('/') }/info.json\"\n\n response = requests.get(url)\n # if response is not 200, raise exception\n if response.status_code != requests.codes.ok:\n response.raise_for_status()\n # if response is not valid json, request will raise\n # requests.exceptions.JSONDecodeError\n # \u2014\u00a0handle or document and let calling code handle?\n resource_info = response.json()\n self.set_hwd(resource_info.get(\"height\"), resource_info.get(\"width\"))\n\n return resource_info\n
"},{"location":"code/#iiif_prezi3.ToReference","title":"ToReference
","text":"Source code in iiif_prezi3/helpers/to_reference.py
class ToReference:\n\n def to_reference(self):\n \"\"\"Returns a Reference object that points to the calling object.\"\"\"\n # Only try to set thumbnail if it's a Class that can have one\n if isinstance(self, (Collection, Manifest, Canvas, AnnotationPage, Annotation, AnnotationCollection, Range)):\n thumbnail = self.thumbnail\n else:\n thumbnail = None\n\n # Currently the skeleton Reference requires a label, but some Referenceable objects may not have one (e.g AnnotationPage)\n # TODO: Remove this when the Schema is updated to have different reference types\n if not self.label:\n self.label = \"\"\n\n # Ensure that we use a specific Reference type if it exists\n if isinstance(self, Manifest):\n target_type = ManifestRef\n elif isinstance(self, Collection):\n target_type = CollectionRef\n elif isinstance(self, Canvas):\n target_type = CanvasRef\n elif isinstance(self, Range):\n target_type = RangeRef\n else:\n target_type = Reference\n\n return target_type(id=self.id, label=self.label, type=self.type, thumbnail=thumbnail)\n
"},{"location":"code/#iiif_prezi3.ToReference.to_reference","title":"to_reference()
","text":"Returns a Reference object that points to the calling object.
Source code in iiif_prezi3/helpers/to_reference.py
def to_reference(self):\n \"\"\"Returns a Reference object that points to the calling object.\"\"\"\n # Only try to set thumbnail if it's a Class that can have one\n if isinstance(self, (Collection, Manifest, Canvas, AnnotationPage, Annotation, AnnotationCollection, Range)):\n thumbnail = self.thumbnail\n else:\n thumbnail = None\n\n # Currently the skeleton Reference requires a label, but some Referenceable objects may not have one (e.g AnnotationPage)\n # TODO: Remove this when the Schema is updated to have different reference types\n if not self.label:\n self.label = \"\"\n\n # Ensure that we use a specific Reference type if it exists\n if isinstance(self, Manifest):\n target_type = ManifestRef\n elif isinstance(self, Collection):\n target_type = CollectionRef\n elif isinstance(self, Canvas):\n target_type = CanvasRef\n elif isinstance(self, Range):\n target_type = RangeRef\n else:\n target_type = Reference\n\n return target_type(id=self.id, label=self.label, type=self.type, thumbnail=thumbnail)\n
"},{"location":"code/#iiif_prezi3.helpers","title":"helpers
","text":""},{"location":"code/#iiif_prezi3.helpers.add_image","title":"add_image
","text":""},{"location":"code/#iiif_prezi3.helpers.add_image.AddImage","title":"AddImage
","text":"Source code in iiif_prezi3/helpers/add_image.py
class AddImage:\n\n def add_image(self, image_url, anno_id=None, anno_page_id=None, **kwargs):\n \"\"\"Adds an image to an existing canvas.\n\n Args:\n image_url (str): An HTTP URL which points to the image.\n anno_id (str): An HTTP URL for the annotation to which the image will be attached.\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n\n Returns:\n anno_page (AnnotationPage): the AnnotationPage with an Annotation and ResourceItem attached.\n \"\"\"\n body = ResourceItem(id=image_url, type='Image', **kwargs)\n annotation = Annotation(id=anno_id, body=body, target=self.id, motivation='painting', type='Annotation')\n anno_page = AnnotationPage(id=anno_page_id, type='AnnotationPage', items=[annotation])\n if not self.items:\n self.items = list()\n self.items.append(anno_page)\n return anno_page\n
"},{"location":"code/#iiif_prezi3.helpers.add_image.AddImage.add_image","title":"add_image(image_url, anno_id=None, anno_page_id=None, **kwargs)
","text":"Adds an image to an existing canvas.
Parameters:
Name Type Description Default image_url
str
An HTTP URL which points to the image.
required anno_id
str
An HTTP URL for the annotation to which the image will be attached.
None
anno_page_id
str
An HTTP URL for the annotation page to which the annotation will be attached.
None
Returns:
Name Type Description anno_page
AnnotationPage
the AnnotationPage with an Annotation and ResourceItem attached.
Source code in iiif_prezi3/helpers/add_image.py
def add_image(self, image_url, anno_id=None, anno_page_id=None, **kwargs):\n \"\"\"Adds an image to an existing canvas.\n\n Args:\n image_url (str): An HTTP URL which points to the image.\n anno_id (str): An HTTP URL for the annotation to which the image will be attached.\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n\n Returns:\n anno_page (AnnotationPage): the AnnotationPage with an Annotation and ResourceItem attached.\n \"\"\"\n body = ResourceItem(id=image_url, type='Image', **kwargs)\n annotation = Annotation(id=anno_id, body=body, target=self.id, motivation='painting', type='Annotation')\n anno_page = AnnotationPage(id=anno_page_id, type='AnnotationPage', items=[annotation])\n if not self.items:\n self.items = list()\n self.items.append(anno_page)\n return anno_page\n
"},{"location":"code/#iiif_prezi3.helpers.add_item","title":"add_item
","text":""},{"location":"code/#iiif_prezi3.helpers.add_item.AddItem","title":"AddItem
","text":"Source code in iiif_prezi3/helpers/add_item.py
class AddItem:\n def add_item(self, item):\n \"\"\"Add a IIIF Prezi3 object to the items list, creating it if it doesn't exist.\n\n Args:\n item (Union[Collection, Manifest, Canvas, AnnotationPage, Annotation, Range, Reference, SpecificResource, Item])): The object to be added\n \"\"\"\n if not self.items:\n self.items = []\n\n # If the item is a Manifest, and the target is a Collection, convert it to a reference\n if isinstance(item, Manifest) and isinstance(self, Collection):\n item = item.to_reference()\n\n self.items.append(item)\n self.items = self.items # Force Pydantic to validate?\n
"},{"location":"code/#iiif_prezi3.helpers.add_item.AddItem.add_item","title":"add_item(item)
","text":"Add a IIIF Prezi3 object to the items list, creating it if it doesn't exist.
Parameters:
Name Type Description Default item
Union[Collection, Manifest, Canvas, AnnotationPage, Annotation, Range, Reference, SpecificResource, Item]
The object to be added
required Source code in iiif_prezi3/helpers/add_item.py
def add_item(self, item):\n \"\"\"Add a IIIF Prezi3 object to the items list, creating it if it doesn't exist.\n\n Args:\n item (Union[Collection, Manifest, Canvas, AnnotationPage, Annotation, Range, Reference, SpecificResource, Item])): The object to be added\n \"\"\"\n if not self.items:\n self.items = []\n\n # If the item is a Manifest, and the target is a Collection, convert it to a reference\n if isinstance(item, Manifest) and isinstance(self, Collection):\n item = item.to_reference()\n\n self.items.append(item)\n self.items = self.items # Force Pydantic to validate?\n
"},{"location":"code/#iiif_prezi3.helpers.add_item.AddItemByReference","title":"AddItemByReference
","text":"Source code in iiif_prezi3/helpers/add_item.py
class AddItemByReference:\n def add_item_by_reference(self, item):\n \"\"\"Add a IIIF Prezi3 object by reference to the items list, creating it if it doesn't exist.\n\n Args:\n item (Union[Manifest, AnnotationPage, Collection, AnnotationCollection, Canvas])): The object to be added\n \"\"\"\n if not self.items:\n self.items = []\n\n item = item.to_reference()\n\n self.items.append(item)\n self.items = self.items # Force Pydantic to validate?\n
"},{"location":"code/#iiif_prezi3.helpers.add_item.AddItemByReference.add_item_by_reference","title":"add_item_by_reference(item)
","text":"Add a IIIF Prezi3 object by reference to the items list, creating it if it doesn't exist.
Parameters:
Name Type Description Default item
Union[Manifest, AnnotationPage, Collection, AnnotationCollection, Canvas]
The object to be added
required Source code in iiif_prezi3/helpers/add_item.py
def add_item_by_reference(self, item):\n \"\"\"Add a IIIF Prezi3 object by reference to the items list, creating it if it doesn't exist.\n\n Args:\n item (Union[Manifest, AnnotationPage, Collection, AnnotationCollection, Canvas])): The object to be added\n \"\"\"\n if not self.items:\n self.items = []\n\n item = item.to_reference()\n\n self.items.append(item)\n self.items = self.items # Force Pydantic to validate?\n
"},{"location":"code/#iiif_prezi3.helpers.add_label","title":"add_label
","text":""},{"location":"code/#iiif_prezi3.helpers.add_label.AddLabel","title":"AddLabel
","text":"Source code in iiif_prezi3/helpers/add_label.py
class AddLabel:\n\n def add_label(self, value, language=None):\n \"\"\"Adds a label to an existing resource.\n\n Args:\n value (Union[str, list]): The label or labels to be added\n language (str): An optional language for the labels. If not provided it will default using the AutoLang configuration.\n \"\"\"\n if not self.label:\n if not language:\n self.label = value\n else:\n if type(value) != list:\n value = [value]\n self.label = {language: value}\n else:\n # fetch as dict not LngString\n curr = self.label\n if not language:\n language = configs['helpers.auto_fields.AutoLang'].auto_lang\n if language in curr:\n curr[language].append(value)\n else:\n if type(value) != list:\n value = [value]\n curr[language] = value\n self.label = curr\n
"},{"location":"code/#iiif_prezi3.helpers.add_label.AddLabel.add_label","title":"add_label(value, language=None)
","text":"Adds a label to an existing resource.
Parameters:
Name Type Description Default value
Union[str, list]
The label or labels to be added
required language
str
An optional language for the labels. If not provided it will default using the AutoLang configuration.
None
Source code in iiif_prezi3/helpers/add_label.py
def add_label(self, value, language=None):\n \"\"\"Adds a label to an existing resource.\n\n Args:\n value (Union[str, list]): The label or labels to be added\n language (str): An optional language for the labels. If not provided it will default using the AutoLang configuration.\n \"\"\"\n if not self.label:\n if not language:\n self.label = value\n else:\n if type(value) != list:\n value = [value]\n self.label = {language: value}\n else:\n # fetch as dict not LngString\n curr = self.label\n if not language:\n language = configs['helpers.auto_fields.AutoLang'].auto_lang\n if language in curr:\n curr[language].append(value)\n else:\n if type(value) != list:\n value = [value]\n curr[language] = value\n self.label = curr\n
"},{"location":"code/#iiif_prezi3.helpers.add_service","title":"add_service
","text":""},{"location":"code/#iiif_prezi3.helpers.add_service.AddService","title":"AddService
","text":"Source code in iiif_prezi3/helpers/add_service.py
class AddService:\n def add_service(self, service):\n \"\"\"Add a IIIF Prezi service to the service list.\n\n Args:\n service (ServiceItem,ServiceItem1,Service): A iiif-prezi ServiceItem.\n \"\"\"\n if isinstance(service, (ServiceItem, ServiceItem1)):\n if not self.service:\n self.service = []\n self.service.append(service)\n self.service = self.service\n else:\n raise TypeError(\"Not a valid IIIF service.\")\n
"},{"location":"code/#iiif_prezi3.helpers.add_service.AddService.add_service","title":"add_service(service)
","text":"Add a IIIF Prezi service to the service list.
Parameters:
Name Type Description Default service
(ServiceItem, ServiceItem1, Service)
A iiif-prezi ServiceItem.
required Source code in iiif_prezi3/helpers/add_service.py
def add_service(self, service):\n \"\"\"Add a IIIF Prezi service to the service list.\n\n Args:\n service (ServiceItem,ServiceItem1,Service): A iiif-prezi ServiceItem.\n \"\"\"\n if isinstance(service, (ServiceItem, ServiceItem1)):\n if not self.service:\n self.service = []\n self.service.append(service)\n self.service = self.service\n else:\n raise TypeError(\"Not a valid IIIF service.\")\n
"},{"location":"code/#iiif_prezi3.helpers.add_thumbnail","title":"add_thumbnail
","text":""},{"location":"code/#iiif_prezi3.helpers.add_thumbnail.AddThumbnail","title":"AddThumbnail
","text":"Source code in iiif_prezi3/helpers/add_thumbnail.py
class AddThumbnail:\n def add_thumbnail(self, image_url, **kwargs):\n \"\"\"Adds a thumbnail to an existing canvas.\n\n Args:\n image_url (str): An HTTP URL which points to the thumbnail.\n **kwargs (): see ResourceItem.\n\n Returns:\n new_thumbnail (ResourceItem): the newly-created thumbnail.\n \"\"\"\n new_thumbnail = ResourceItem(id=image_url, type='Image', **kwargs)\n if not self.thumbnail:\n self.thumbnail = list()\n self.thumbnail.append(new_thumbnail)\n return new_thumbnail\n
"},{"location":"code/#iiif_prezi3.helpers.add_thumbnail.AddThumbnail.add_thumbnail","title":"add_thumbnail(image_url, **kwargs)
","text":"Adds a thumbnail to an existing canvas.
Parameters:
Name Type Description Default image_url
str
An HTTP URL which points to the thumbnail.
required **kwargs
see ResourceItem.
{}
Returns:
Name Type Description new_thumbnail
ResourceItem
the newly-created thumbnail.
Source code in iiif_prezi3/helpers/add_thumbnail.py
def add_thumbnail(self, image_url, **kwargs):\n \"\"\"Adds a thumbnail to an existing canvas.\n\n Args:\n image_url (str): An HTTP URL which points to the thumbnail.\n **kwargs (): see ResourceItem.\n\n Returns:\n new_thumbnail (ResourceItem): the newly-created thumbnail.\n \"\"\"\n new_thumbnail = ResourceItem(id=image_url, type='Image', **kwargs)\n if not self.thumbnail:\n self.thumbnail = list()\n self.thumbnail.append(new_thumbnail)\n return new_thumbnail\n
"},{"location":"code/#iiif_prezi3.helpers.annotation_helpers","title":"annotation_helpers
","text":""},{"location":"code/#iiif_prezi3.helpers.annotation_helpers.AnnotationHelpers","title":"AnnotationHelpers
","text":"Source code in iiif_prezi3/helpers/annotation_helpers.py
class AnnotationHelpers:\n\n def add_annotation(self, annotation, anno_page_id=None):\n \"\"\"Adds the annotation object to the (AnnotationPage object in the) annotations property.\n\n Creates an AnnotationPage object if it doesn't exist.\n\n Args:\n annotation (Annotation): the Annotation to add\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n\n Returns:\n annotation (Annotation): the Annotation attached to the AnnotationPage.\n\n \"\"\"\n if not self.annotations:\n self.annotations = list()\n\n if len(self.annotations) == 0:\n # add empty AnnotationPage\n anno_page = AnnotationPage(id=anno_page_id, items=[])\n self.annotations.append(anno_page)\n else:\n anno_page = self.annotations[0]\n\n anno_page.items.append(annotation)\n\n return annotation\n\n def make_annotation(self, anno_page_id=None, **kwargs):\n \"\"\"Creates an annotation object and adds it to the annotations property using .add_annotation().\n\n Args:\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n **kwargs (): see Annotation.\n \"\"\"\n annotation = Annotation(**kwargs)\n self.add_annotation(annotation, anno_page_id=anno_page_id)\n return annotation\n
"},{"location":"code/#iiif_prezi3.helpers.annotation_helpers.AnnotationHelpers.add_annotation","title":"add_annotation(annotation, anno_page_id=None)
","text":"Adds the annotation object to the (AnnotationPage object in the) annotations property.
Creates an AnnotationPage object if it doesn't exist.
Parameters:
Name Type Description Default annotation
Annotation
the Annotation to add
required anno_page_id
str
An HTTP URL for the annotation page to which the annotation will be attached.
None
Returns:
Name Type Description annotation
Annotation
the Annotation attached to the AnnotationPage.
Source code in iiif_prezi3/helpers/annotation_helpers.py
def add_annotation(self, annotation, anno_page_id=None):\n \"\"\"Adds the annotation object to the (AnnotationPage object in the) annotations property.\n\n Creates an AnnotationPage object if it doesn't exist.\n\n Args:\n annotation (Annotation): the Annotation to add\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n\n Returns:\n annotation (Annotation): the Annotation attached to the AnnotationPage.\n\n \"\"\"\n if not self.annotations:\n self.annotations = list()\n\n if len(self.annotations) == 0:\n # add empty AnnotationPage\n anno_page = AnnotationPage(id=anno_page_id, items=[])\n self.annotations.append(anno_page)\n else:\n anno_page = self.annotations[0]\n\n anno_page.items.append(annotation)\n\n return annotation\n
"},{"location":"code/#iiif_prezi3.helpers.annotation_helpers.AnnotationHelpers.make_annotation","title":"make_annotation(anno_page_id=None, **kwargs)
","text":"Creates an annotation object and adds it to the annotations property using .add_annotation().
Parameters:
Name Type Description Default anno_page_id
str
An HTTP URL for the annotation page to which the annotation will be attached.
None
**kwargs
see Annotation.
{}
Source code in iiif_prezi3/helpers/annotation_helpers.py
def make_annotation(self, anno_page_id=None, **kwargs):\n \"\"\"Creates an annotation object and adds it to the annotations property using .add_annotation().\n\n Args:\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n **kwargs (): see Annotation.\n \"\"\"\n annotation = Annotation(**kwargs)\n self.add_annotation(annotation, anno_page_id=anno_page_id)\n return annotation\n
"},{"location":"code/#iiif_prezi3.helpers.create_canvas_from_iiif","title":"create_canvas_from_iiif
","text":""},{"location":"code/#iiif_prezi3.helpers.create_canvas_from_iiif.CreateCanvasFromIIIF","title":"CreateCanvasFromIIIF
","text":"Source code in iiif_prezi3/helpers/create_canvas_from_iiif.py
class CreateCanvasFromIIIF:\n # should probably be added to canvas helpers\n\n def create_canvas_from_iiif(self, url, anno_id=None, anno_page_id=None, **kwargs):\n \"\"\"Create a canvas from a IIIF Image URL.\n\n Creates a canvas from a IIIF Image service passing any kwargs to the Canvas.\n\n Args:\n url (str): An HTTP URL at which at a IIIF Image is available.\n anno_id (str): An HTTP URL for the annotation to which the image will be attached.\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n **kwargs (): see Canvas\n\n Returns:\n canvas (Canvas): the Canvas created from the IIIF Image.\n\n \"\"\"\n canvas = Canvas(**kwargs)\n\n body = ResourceItem(id=\"http://example.com\", type=\"Image\")\n infoJson = body.set_hwd_from_iiif(url)\n\n # Will need to handle IIIF 2...\n if 'type' not in infoJson:\n # Assume v2\n\n # V2 profile contains profile URI plus extra features\n profile = ''\n for item in infoJson['profile']:\n if isinstance(item, str):\n profile = item\n break\n\n service = ServiceItem1(id=infoJson['@id'], profile=profile, type=\"ImageService2\")\n body.service = [service]\n body.id = f'{infoJson[\"@id\"]}/full/full/0/default.jpg'\n body.format = \"image/jpeg\"\n else:\n service = ServiceItem(id=infoJson['id'], profile=infoJson['profile'], type=infoJson['type'])\n body.service = [service]\n body.id = f'{infoJson[\"id\"]}/full/max/0/default.jpg'\n body.format = \"image/jpeg\"\n\n annotation = Annotation(id=anno_id, motivation='painting', body=body, target=canvas.id)\n\n annotationPage = AnnotationPage(id=anno_page_id)\n annotationPage.add_item(annotation)\n\n canvas.add_item(annotationPage)\n canvas.set_hwd(infoJson['height'], infoJson['width'])\n\n return canvas\n\n def make_canvas_from_iiif(self, url, **kwargs):\n canvas = self.create_canvas_from_iiif(url, **kwargs)\n\n self.add_item(canvas)\n return canvas\n
"},{"location":"code/#iiif_prezi3.helpers.create_canvas_from_iiif.CreateCanvasFromIIIF.create_canvas_from_iiif","title":"create_canvas_from_iiif(url, anno_id=None, anno_page_id=None, **kwargs)
","text":"Create a canvas from a IIIF Image URL.
Creates a canvas from a IIIF Image service passing any kwargs to the Canvas.
Parameters:
Name Type Description Default url
str
An HTTP URL at which at a IIIF Image is available.
required anno_id
str
An HTTP URL for the annotation to which the image will be attached.
None
anno_page_id
str
An HTTP URL for the annotation page to which the annotation will be attached.
None
**kwargs
see Canvas
{}
Returns:
Name Type Description canvas
Canvas
the Canvas created from the IIIF Image.
Source code in iiif_prezi3/helpers/create_canvas_from_iiif.py
def create_canvas_from_iiif(self, url, anno_id=None, anno_page_id=None, **kwargs):\n \"\"\"Create a canvas from a IIIF Image URL.\n\n Creates a canvas from a IIIF Image service passing any kwargs to the Canvas.\n\n Args:\n url (str): An HTTP URL at which at a IIIF Image is available.\n anno_id (str): An HTTP URL for the annotation to which the image will be attached.\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n **kwargs (): see Canvas\n\n Returns:\n canvas (Canvas): the Canvas created from the IIIF Image.\n\n \"\"\"\n canvas = Canvas(**kwargs)\n\n body = ResourceItem(id=\"http://example.com\", type=\"Image\")\n infoJson = body.set_hwd_from_iiif(url)\n\n # Will need to handle IIIF 2...\n if 'type' not in infoJson:\n # Assume v2\n\n # V2 profile contains profile URI plus extra features\n profile = ''\n for item in infoJson['profile']:\n if isinstance(item, str):\n profile = item\n break\n\n service = ServiceItem1(id=infoJson['@id'], profile=profile, type=\"ImageService2\")\n body.service = [service]\n body.id = f'{infoJson[\"@id\"]}/full/full/0/default.jpg'\n body.format = \"image/jpeg\"\n else:\n service = ServiceItem(id=infoJson['id'], profile=infoJson['profile'], type=infoJson['type'])\n body.service = [service]\n body.id = f'{infoJson[\"id\"]}/full/max/0/default.jpg'\n body.format = \"image/jpeg\"\n\n annotation = Annotation(id=anno_id, motivation='painting', body=body, target=canvas.id)\n\n annotationPage = AnnotationPage(id=anno_page_id)\n annotationPage.add_item(annotation)\n\n canvas.add_item(annotationPage)\n canvas.set_hwd(infoJson['height'], infoJson['width'])\n\n return canvas\n
"},{"location":"code/#iiif_prezi3.helpers.make_canvas","title":"make_canvas
","text":""},{"location":"code/#iiif_prezi3.helpers.make_canvas.MakeCanvas","title":"MakeCanvas
","text":"Source code in iiif_prezi3/helpers/make_canvas.py
class MakeCanvas:\n\n def make_canvas(self, **kwargs):\n \"\"\"Add a Canvas to a Manifest.\n\n Creates a new Canvas, appends it to the\n calling Manifest items and returns the newly created Canvas.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n canvas = Canvas(**kwargs)\n self.add_item(canvas)\n return canvas\n
"},{"location":"code/#iiif_prezi3.helpers.make_canvas.MakeCanvas.make_canvas","title":"make_canvas(**kwargs)
","text":"Add a Canvas to a Manifest.
Creates a new Canvas, appends it to the calling Manifest items and returns the newly created Canvas. Accepts keyword arguments to customize the resulting instance.
Source code in iiif_prezi3/helpers/make_canvas.py
def make_canvas(self, **kwargs):\n \"\"\"Add a Canvas to a Manifest.\n\n Creates a new Canvas, appends it to the\n calling Manifest items and returns the newly created Canvas.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n canvas = Canvas(**kwargs)\n self.add_item(canvas)\n return canvas\n
"},{"location":"code/#iiif_prezi3.helpers.make_collection","title":"make_collection
","text":""},{"location":"code/#iiif_prezi3.helpers.make_collection.MakeCollection","title":"MakeCollection
","text":"Source code in iiif_prezi3/helpers/make_collection.py
class MakeCollection:\n\n def make_collection(self, **kwargs):\n \"\"\"Create a Collection.\n\n Creates a new collection, adds it to the calling Collection `items`\n and returns the newly created object. Accepts keyword arguments to\n customize the resulting instance.\n \"\"\"\n child_collection = Collection(**kwargs)\n self.add_item(child_collection)\n return child_collection\n
"},{"location":"code/#iiif_prezi3.helpers.make_collection.MakeCollection.make_collection","title":"make_collection(**kwargs)
","text":"Create a Collection.
Creates a new collection, adds it to the calling Collection items
and returns the newly created object. Accepts keyword arguments to customize the resulting instance.
Source code in iiif_prezi3/helpers/make_collection.py
def make_collection(self, **kwargs):\n \"\"\"Create a Collection.\n\n Creates a new collection, adds it to the calling Collection `items`\n and returns the newly created object. Accepts keyword arguments to\n customize the resulting instance.\n \"\"\"\n child_collection = Collection(**kwargs)\n self.add_item(child_collection)\n return child_collection\n
"},{"location":"code/#iiif_prezi3.helpers.make_manifest","title":"make_manifest
","text":""},{"location":"code/#iiif_prezi3.helpers.make_manifest.MakeManifest","title":"MakeManifest
","text":"Source code in iiif_prezi3/helpers/make_manifest.py
class MakeManifest:\n\n def make_manifest(self, **kwargs):\n \"\"\"Add a Manifest to a Collection.\n\n Creates a new Manifest, adds a Reference to it to the\n calling Collection items and returns the newly created Manifest.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n manifest = Manifest(**kwargs)\n self.add_item(manifest)\n return manifest\n
"},{"location":"code/#iiif_prezi3.helpers.make_manifest.MakeManifest.make_manifest","title":"make_manifest(**kwargs)
","text":"Add a Manifest to a Collection.
Creates a new Manifest, adds a Reference to it to the calling Collection items and returns the newly created Manifest. Accepts keyword arguments to customize the resulting instance.
Source code in iiif_prezi3/helpers/make_manifest.py
def make_manifest(self, **kwargs):\n \"\"\"Add a Manifest to a Collection.\n\n Creates a new Manifest, adds a Reference to it to the\n calling Collection items and returns the newly created Manifest.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n manifest = Manifest(**kwargs)\n self.add_item(manifest)\n return manifest\n
"},{"location":"code/#iiif_prezi3.helpers.make_range","title":"make_range
","text":""},{"location":"code/#iiif_prezi3.helpers.make_range.MakeRange","title":"MakeRange
","text":"Source code in iiif_prezi3/helpers/make_range.py
class MakeRange:\n\n def make_range(self, **kwargs):\n \"\"\"Create a Range and add it to the calling Collection or Range.\n\n Creates a new Range, adds it to the calling object and returns the newly created Range.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n range = Range(**kwargs)\n if type(self) == Manifest:\n if self.structures:\n self.structures.append(range)\n else:\n self.structures = [range]\n elif type(self) == Range:\n self.add_item(range)\n return range\n
"},{"location":"code/#iiif_prezi3.helpers.make_range.MakeRange.make_range","title":"make_range(**kwargs)
","text":"Create a Range and add it to the calling Collection or Range.
Creates a new Range, adds it to the calling object and returns the newly created Range. Accepts keyword arguments to customize the resulting instance.
Source code in iiif_prezi3/helpers/make_range.py
def make_range(self, **kwargs):\n \"\"\"Create a Range and add it to the calling Collection or Range.\n\n Creates a new Range, adds it to the calling object and returns the newly created Range.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n range = Range(**kwargs)\n if type(self) == Manifest:\n if self.structures:\n self.structures.append(range)\n else:\n self.structures = [range]\n elif type(self) == Range:\n self.add_item(range)\n return range\n
"},{"location":"code/#iiif_prezi3.helpers.make_service","title":"make_service
","text":""},{"location":"code/#iiif_prezi3.helpers.make_service.MakeService","title":"MakeService
","text":"Source code in iiif_prezi3/helpers/make_service.py
class MakeService:\n def make_service(self, id, type, version=3, **kwargs):\n \"\"\"Make a IIIF Prezi service of the desired IIIF API version and adds it to the service list.\n\n Args:\n id (AnyUrl): The id of the service.\n type (str): The type of the service.\n version (int): The API version of the service. Defaults to 3.\n **kwargs (): Arbitrary keyword arguments.\n\n Raises:\n ValueError: If an invalid IIIF API version is provided.\n\n Returns:\n service (Union[ServiceItem, ServiceItem1]): A service instance of the selected version.\n \"\"\"\n serviceversions = {\n 2: ServiceItem1,\n 3: ServiceItem\n }\n if version not in serviceversions:\n raise ValueError(f\"Version: {version} is not a valid IIIF API service version.\")\n service = serviceversions[version](id=id, type=type, **kwargs)\n self.add_service(service)\n return service\n
"},{"location":"code/#iiif_prezi3.helpers.make_service.MakeService.make_service","title":"make_service(id, type, version=3, **kwargs)
","text":"Make a IIIF Prezi service of the desired IIIF API version and adds it to the service list.
Parameters:
Name Type Description Default id
AnyUrl
The id of the service.
required type
str
The type of the service.
required version
int
The API version of the service. Defaults to 3.
3
**kwargs
Arbitrary keyword arguments.
{}
Raises:
Type Description ValueError
If an invalid IIIF API version is provided.
Returns:
Name Type Description service
Union[ServiceItem, ServiceItem1]
A service instance of the selected version.
Source code in iiif_prezi3/helpers/make_service.py
def make_service(self, id, type, version=3, **kwargs):\n \"\"\"Make a IIIF Prezi service of the desired IIIF API version and adds it to the service list.\n\n Args:\n id (AnyUrl): The id of the service.\n type (str): The type of the service.\n version (int): The API version of the service. Defaults to 3.\n **kwargs (): Arbitrary keyword arguments.\n\n Raises:\n ValueError: If an invalid IIIF API version is provided.\n\n Returns:\n service (Union[ServiceItem, ServiceItem1]): A service instance of the selected version.\n \"\"\"\n serviceversions = {\n 2: ServiceItem1,\n 3: ServiceItem\n }\n if version not in serviceversions:\n raise ValueError(f\"Version: {version} is not a valid IIIF API service version.\")\n service = serviceversions[version](id=id, type=type, **kwargs)\n self.add_service(service)\n return service\n
"},{"location":"code/#iiif_prezi3.helpers.set_hwd","title":"set_hwd
","text":""},{"location":"code/#iiif_prezi3.helpers.set_hwd.SetHwd","title":"SetHwd
","text":"Source code in iiif_prezi3/helpers/set_hwd.py
class SetHwd:\n def set_hwd(self, height=None, width=None, duration=None):\n \"\"\"Set the height, width, and duration properties allowing nulls.\n\n Args:\n height (int): The height of the resource or the canvas\n width (int): The width of the resource or the canvas\n duration (float): The duration of the resource\n \"\"\"\n if not (duration or height or width):\n raise TypeError(\"At least one of height, width, or duration must be set\")\n if height and not width:\n raise TypeError(\"width must be set if height is set\")\n if width and not height:\n raise TypeError(\"height must be set if width is set\")\n self.height = height\n self.width = width\n self.duration = duration\n
"},{"location":"code/#iiif_prezi3.helpers.set_hwd.SetHwd.set_hwd","title":"set_hwd(height=None, width=None, duration=None)
","text":"Set the height, width, and duration properties allowing nulls.
Parameters:
Name Type Description Default height
int
The height of the resource or the canvas
None
width
int
The width of the resource or the canvas
None
duration
float
The duration of the resource
None
Source code in iiif_prezi3/helpers/set_hwd.py
def set_hwd(self, height=None, width=None, duration=None):\n \"\"\"Set the height, width, and duration properties allowing nulls.\n\n Args:\n height (int): The height of the resource or the canvas\n width (int): The width of the resource or the canvas\n duration (float): The duration of the resource\n \"\"\"\n if not (duration or height or width):\n raise TypeError(\"At least one of height, width, or duration must be set\")\n if height and not width:\n raise TypeError(\"width must be set if height is set\")\n if width and not height:\n raise TypeError(\"height must be set if width is set\")\n self.height = height\n self.width = width\n self.duration = duration\n
"},{"location":"code/#iiif_prezi3.helpers.set_hwd_from_file","title":"set_hwd_from_file
","text":""},{"location":"code/#iiif_prezi3.helpers.set_hwd_from_file.SetHeightWidthDurationFileHelper","title":"SetHeightWidthDurationFileHelper
","text":"Source code in iiif_prezi3/helpers/set_hwd_from_file.py
class SetHeightWidthDurationFileHelper:\n def set_hwd_from_file(self, file_path_or_object):\n \"\"\"Introspect a file and set the height, width, and duration properties.\n\n Args:\n file_path_or_object (Union[str, fp]): the file path or file object to introspect\n \"\"\"\n if isinstance(file_path_or_object, str) or isinstance(file_path_or_object, os.PathLike):\n filetype, _ = mimetypes.guess_type(file_path_or_object)\n if not filetype.startswith(\"image/\"):\n raise NotImplementedError\n\n tmp_image = Image.open(file_path_or_object)\n w, h = tmp_image.size\n self.set_hwd(h, w, None)\n tmp_image.close()\n
"},{"location":"code/#iiif_prezi3.helpers.set_hwd_from_file.SetHeightWidthDurationFileHelper.set_hwd_from_file","title":"set_hwd_from_file(file_path_or_object)
","text":"Introspect a file and set the height, width, and duration properties.
Parameters:
Name Type Description Default file_path_or_object
Union[str, fp]
the file path or file object to introspect
required Source code in iiif_prezi3/helpers/set_hwd_from_file.py
def set_hwd_from_file(self, file_path_or_object):\n \"\"\"Introspect a file and set the height, width, and duration properties.\n\n Args:\n file_path_or_object (Union[str, fp]): the file path or file object to introspect\n \"\"\"\n if isinstance(file_path_or_object, str) or isinstance(file_path_or_object, os.PathLike):\n filetype, _ = mimetypes.guess_type(file_path_or_object)\n if not filetype.startswith(\"image/\"):\n raise NotImplementedError\n\n tmp_image = Image.open(file_path_or_object)\n w, h = tmp_image.size\n self.set_hwd(h, w, None)\n tmp_image.close()\n
"},{"location":"code/#iiif_prezi3.helpers.set_hwd_from_iiif","title":"set_hwd_from_iiif
","text":""},{"location":"code/#iiif_prezi3.helpers.set_hwd_from_iiif.SetHwdFromIIIF","title":"SetHwdFromIIIF
","text":"Source code in iiif_prezi3/helpers/set_hwd_from_iiif.py
class SetHwdFromIIIF:\n # should probably be added to canvas helpers\n\n def set_hwd_from_iiif(self, url):\n \"\"\"Set height and width on a Canvas object.\n\n Requests IIIF Image information remotely for an\n image resource and sets resulting height and width.\n This method will return the info.json\n\n Args:\n url (str): An HTTP URL for the IIIF image endpoint.\n \"\"\"\n # resource url may or may not end with info.json;\n # add if not present\n if not url.endswith(\"info.json\"):\n url = f\"{ url.rstrip('/') }/info.json\"\n\n response = requests.get(url)\n # if response is not 200, raise exception\n if response.status_code != requests.codes.ok:\n response.raise_for_status()\n # if response is not valid json, request will raise\n # requests.exceptions.JSONDecodeError\n # \u2014\u00a0handle or document and let calling code handle?\n resource_info = response.json()\n self.set_hwd(resource_info.get(\"height\"), resource_info.get(\"width\"))\n\n return resource_info\n
"},{"location":"code/#iiif_prezi3.helpers.set_hwd_from_iiif.SetHwdFromIIIF.set_hwd_from_iiif","title":"set_hwd_from_iiif(url)
","text":"Set height and width on a Canvas object.
Requests IIIF Image information remotely for an image resource and sets resulting height and width. This method will return the info.json
Parameters:
Name Type Description Default url
str
An HTTP URL for the IIIF image endpoint.
required Source code in iiif_prezi3/helpers/set_hwd_from_iiif.py
def set_hwd_from_iiif(self, url):\n \"\"\"Set height and width on a Canvas object.\n\n Requests IIIF Image information remotely for an\n image resource and sets resulting height and width.\n This method will return the info.json\n\n Args:\n url (str): An HTTP URL for the IIIF image endpoint.\n \"\"\"\n # resource url may or may not end with info.json;\n # add if not present\n if not url.endswith(\"info.json\"):\n url = f\"{ url.rstrip('/') }/info.json\"\n\n response = requests.get(url)\n # if response is not 200, raise exception\n if response.status_code != requests.codes.ok:\n response.raise_for_status()\n # if response is not valid json, request will raise\n # requests.exceptions.JSONDecodeError\n # \u2014\u00a0handle or document and let calling code handle?\n resource_info = response.json()\n self.set_hwd(resource_info.get(\"height\"), resource_info.get(\"width\"))\n\n return resource_info\n
"},{"location":"code/#iiif_prezi3.helpers.to_reference","title":"to_reference
","text":""},{"location":"code/#iiif_prezi3.helpers.to_reference.ToReference","title":"ToReference
","text":"Source code in iiif_prezi3/helpers/to_reference.py
class ToReference:\n\n def to_reference(self):\n \"\"\"Returns a Reference object that points to the calling object.\"\"\"\n # Only try to set thumbnail if it's a Class that can have one\n if isinstance(self, (Collection, Manifest, Canvas, AnnotationPage, Annotation, AnnotationCollection, Range)):\n thumbnail = self.thumbnail\n else:\n thumbnail = None\n\n # Currently the skeleton Reference requires a label, but some Referenceable objects may not have one (e.g AnnotationPage)\n # TODO: Remove this when the Schema is updated to have different reference types\n if not self.label:\n self.label = \"\"\n\n # Ensure that we use a specific Reference type if it exists\n if isinstance(self, Manifest):\n target_type = ManifestRef\n elif isinstance(self, Collection):\n target_type = CollectionRef\n elif isinstance(self, Canvas):\n target_type = CanvasRef\n elif isinstance(self, Range):\n target_type = RangeRef\n else:\n target_type = Reference\n\n return target_type(id=self.id, label=self.label, type=self.type, thumbnail=thumbnail)\n
"},{"location":"code/#iiif_prezi3.helpers.to_reference.ToReference.to_reference","title":"to_reference()
","text":"Returns a Reference object that points to the calling object.
Source code in iiif_prezi3/helpers/to_reference.py
def to_reference(self):\n \"\"\"Returns a Reference object that points to the calling object.\"\"\"\n # Only try to set thumbnail if it's a Class that can have one\n if isinstance(self, (Collection, Manifest, Canvas, AnnotationPage, Annotation, AnnotationCollection, Range)):\n thumbnail = self.thumbnail\n else:\n thumbnail = None\n\n # Currently the skeleton Reference requires a label, but some Referenceable objects may not have one (e.g AnnotationPage)\n # TODO: Remove this when the Schema is updated to have different reference types\n if not self.label:\n self.label = \"\"\n\n # Ensure that we use a specific Reference type if it exists\n if isinstance(self, Manifest):\n target_type = ManifestRef\n elif isinstance(self, Collection):\n target_type = CollectionRef\n elif isinstance(self, Canvas):\n target_type = CanvasRef\n elif isinstance(self, Range):\n target_type = RangeRef\n else:\n target_type = Reference\n\n return target_type(id=self.id, label=self.label, type=self.type, thumbnail=thumbnail)\n
"},{"location":"generate-schema/","title":"Generating the Schema","text":"Install the datamodl-codegen program which will convert a JSON schema into python code. Either follow the instructions here or run:
pip install datamodel-code-generator\n
Then in the iiif-prezi3 code directory run:
datamodel-codegen --input ../../iiif/presentation-validator/schema/iiif_3_0.json --input-file-type jsonschema --use-default --base-class base.Base --output skeleton.py\n
Replacing the path to your iiif schema file with where ever you have downloaded the iiif_3_0.json file.
"},{"location":"getting-started-using-iiifprezi3-without-helpermethods/","title":"Getting started: using iiifprezi3 without helper methods","text":"Note
iiif-prezi3
offers useful helper methods for adding IIIF resources, it is preferable to use them when possible.
For special needs, not addressed by the helper methods, users may take advantage directly of the Python classes generated by datamodel-code-generator. These classes can be used for generating instances of IIIF objects described in the presentation API v.3.
In the following lines of code, we will create a manifest and two canvases using directly the pydantic classes:
import iiif_prezi3\namanifest = iiif_prezi3.Manifest(id='http://iiif.example.org/prezi/Manifest/0', label={'en': ['default label']})\nacanvas = iiif_prezi3.Canvas(id='http://iiif.example.org/prezi/Manifest/0/canvas/01', label={'en': ['default label']})\nasecondcanvas = iiif_prezi3.Canvas(id='http://iiif.example.org/prezi/Manifest/0/canvas/02', label={'en': ['second label']})\n
For constructing nested objects we have to assign to the items property a list containing the valid IIIF objects accepted by the class:
amanifest.items = [acanvas,asecondcanvas]\n
If we try to set the items property of the manifest items to a string pydantic
will rise a ValidationError
:
amanifest.items = [\"this shouldn't be here\"]\n
Warning
Be aware that appending to the items list after that the items property has been assigned :
amanifest.items.append(\"this shouldn't be here\")\n
will not raise any error regarding the input.
print(amanifest.json(exclude_unset=True,indent=2))\n
{\n \"id\": \"http://iiif.example.org/prezi/Manifest/0\",\n \"type\": \"Manifest\",\n \"label\": {},\n \"items\": [\n {\n \"id\": \"http://iiif.example.org/prezi/Manifest/0/canvas/01\",\n \"type\": \"Canvas\",\n \"label\": {}\n },\n {\n \"id\": \"http://iiif.example.org/prezi/Manifest/0/canvas/02\",\n \"type\": \"Canvas\",\n \"label\": {}\n },\n \"this shouldn't be here\"\n ]\n}\n
Of course, in most of the use cases, canvases will be created dynamically so a possible approach for constructing the manifest can be the following:
canvases = []\nfor i in range(3):\n canvasid = f'http://iiif.example.org/prezi/CanvasID/{i}'\n aservice = {\n \"id\": \"https://example.org/iiif/book1/page2\",\n \"type\": \"ImageService3\",\n \"profile\": \"level2\"\n }\n anannotation = iiif_prezi3.Annotation(type='Annotation',id=canvasid+'/annotation/0',target=canvasid)\n anannotation.motivation = 'painting'\n # aresource = Resource(service=[aservice],type='Resource')\n anannotation.body = iiif_prezi3.ResourceItem(service=[aservice],id=canvasid+'/annotation/resource',type='Image')\n anannotationpage = iiif_prezi3.AnnotationPage(type='AnnotationPage')\n anannotationpage.items = [anannotation]\n acanvas.items = [anannotationpage]\n canvases.append(acanvas)\n\namanifest.items = canvases\n
Notice that the canvases list is created at the beginning but is assigned to the items property of the manifest only once at the end, in this way pydantic will validate the list.
Warning
Keep in mind that objects contained in the canvases
list are references in the manifest items, hence any modification on the original object will affect the object inside the manifest. This holds true for any object added to the model.
"},{"location":"write-helper-method/","title":"Helper methods","text":"Helper methods in iiif-prezi3
allow functionality for common use cases to be included in the package. Helpers that are general can be loaded and used by the user as required, and those that target specific schema objects (e.g a helper to add a Canvas to a Manifest) are monkeypatched onto the relevant schema class at load time.
"},{"location":"write-helper-method/#location-and-structure","title":"Location and structure","text":"Helper methods should be located in Python files inside the helpers/
directory. Direct helper methods that take schema objects as arguments can be singular functions, whereas those which are designed to add new functions or properties to existing schema classes must themselves be containing inside a class, to enable them to be monkeypatched in correctly.
"},{"location":"write-helper-method/#accessing-schema-objects","title":"Accessing Schema Objects","text":"Relevant schema classes can be loaded from the skeleton.py
file in the main iiif-prezi3
package by using a relative import:
from ..skeleton import Manifest\n
"},{"location":"write-helper-method/#monkeypatching-onto-schema-classes","title":"Monkeypatching onto Schema classes","text":"If the helper targets a class from the main IIIF Presentation 3 schema, then it can be monkeypatched onto that class at runtime using the iiif_prezi3.loader.monkeypatch_schema()
method. This function takes two arguments: the class to target, and the class(es) containing the helper methods, either as a single object or a list. Add the monkeypatch function call at the end of your helper file, and it will be run when the helper file is imported by the main package (as detailed below).
from ..skeleton import Manifest\nfrom ..loader import monkeypatch_schema\n\n\nclass MyHelper:\n def helper_function(self):\n return \"I am a Manifest helper\"\n\nmonkeypatch_schema(Manifest, MyHelper)\n
"},{"location":"write-helper-method/#including-helpers-in-the-main-package","title":"Including helpers in the main package","text":"To enable a helper, import it via relative import in the helpers/__init__.py
file. This will include the functions directly in the namespace of iiif_prezi3.helpers
, which in turn is imported in its entirety by the __init__.py
file of the main package.
In helpers/__init__.py
:
from .example_helper import MyHelper\n
Allowing:
>>> from iiif_prezi3 import Manifest\n>>> m = Manifest(id=\"https://example.com/manifest\", type=\"Manifest\", label={\"en\":\"Example Manifest\"})\n>>> m.helper_function()\n'I am a Manifest helper'\n
"},{"location":"recipes/","title":"Cookbook Recipes","text":"This section of the documentation attempts to provide a \"learn by example\" resource, by reproducing the IIIF Cookbook recipes using the iiif-prezi3
library.
Where possible, the helper methods and other conveniences of iiif-prezi3
are leveraged, with secondary examples showing alternate methods of creating the recipe JSON.
If you would like to contribute to this section, please see the Cookbook recipe examples issue in the project's GitHub repository.
"},{"location":"recipes/0001-mvm-image/","title":"Simplest Manifest - Single Image File","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0001-mvm-image/ JSON-LD: https://iiif.io/api/cookbook/recipe/0001-mvm-image/manifest.json"},{"location":"recipes/0001-mvm-image/#method-1-using-the-make_canvas-and-add_image-helpers","title":"Method 1 - Using the make_canvas
and add_image
helpers","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0001-mvm-image\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\", label=\"Single Image Example\")\ncanvas = manifest.make_canvas(id=f\"{base_url}/canvas/p1\", height=1800, width=1200)\nanno_page = canvas.add_image(image_url=\"http://iiif.io/api/presentation/2.1/example/fixtures/resources/page1-full.png\",\n anno_page_id=f\"{base_url}/page/p1/1\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n format=\"image/png\",\n height=1800,\n width=1200\n )\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0001-mvm-image/#method-2-building-the-structure-manually-and-using-the-add_item-helper","title":"Method 2 - Building the structure manually and using the add_item
helper","text":"from iiif_prezi3 import Manifest, Canvas, AnnotationPage, Annotation, ResourceItem, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0001-mvm-image\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\", label=\"Single Image Example\")\ncanvas = Canvas(id=f\"{base_url}/canvas/p1\", height=1800, width=1200)\nanno_body = ResourceItem(id=\"http://iiif.io/api/presentation/2.1/example/fixtures/resources/page1-full.png\",\n type=\"Image\",\n format=\"image/png\",\n height=1800,\n width=1200)\nanno_page = AnnotationPage(id=f\"{base_url}/page/p1/1\")\nanno = Annotation(id=f\"{base_url}/annotation/p0001-image\",\n motivation=\"painting\",\n body=anno_body,\n target=canvas.id)\nanno_page.add_item(anno)\ncanvas.add_item(anno_page)\nmanifest.add_item(canvas)\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0002-mvm-audio/","title":"Simplest Manifest - Audio","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0002-mvm-audio/ JSON-LD: https://iiif.io/api/cookbook/recipe/0002-mvm-audio/manifest.json"},{"location":"recipes/0002-mvm-audio/#method-1-building-the-structure-and-using-the-add_item-helper","title":"Method 1 - Building the structure and using the add_item
helper","text":"from iiif_prezi3 import Manifest, AnnotationPage, Annotation, ResourceItem, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0002-mvm-audio\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\", label=\"Simplest Audio Example 1\")\ncanvas = manifest.make_canvas(id=f\"{base_url}/canvas\", duration=1985.024)\nanno_body = ResourceItem(id=\"https://fixtures.iiif.io/audio/indiana/mahler-symphony-3/CD1/medium/128Kbps.mp4\",\n type=\"Sound\",\n format=\"audio/mp4\",\n duration=1985.024)\nanno_page = AnnotationPage(id=f\"{base_url}/canvas/page\")\nanno = Annotation(id=f\"{base_url}/canvas/page/annotation\",\n motivation=\"painting\",\n body=anno_body,\n target=canvas.id)\nanno_page.add_item(anno)\ncanvas.add_item(anno_page)\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0003-mvm-video/","title":"Simplest Manifest - Video","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0003-mvm-video/ JSON-LD: https://iiif.io/api/cookbook/recipe/0003-mvm-video/manifest.json"},{"location":"recipes/0003-mvm-video/#method-1-building-the-structure-manually-and-using-the-add_item-helper","title":"Method 1 - Building the structure manually and using the add_item
helper","text":"from iiif_prezi3 import Manifest, AnnotationPage, Annotation, ResourceItem, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0003-mvm-video\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\", label=\"Video Example 3\")\ncanvas = manifest.make_canvas(id=f\"{base_url}/canvas\")\nanno_body = ResourceItem(id=\"https://fixtures.iiif.io/video/indiana/lunchroom_manners/high/lunchroom_manners_1024kb.mp4\",\n type=\"Video\",\n format=\"video/mp4\")\nanno_page = AnnotationPage(id=f\"{base_url}/canvas/page\")\nanno = Annotation(id=f\"{base_url}/canvas/page/annotation\",\n motivation=\"painting\",\n body=anno_body,\n target=canvas.id)\n\nhwd = {\"height\": 360, \"width\": 480, \"duration\": 572.034}\nanno_body.set_hwd(**hwd)\ncanvas.set_hwd(**hwd)\n\nanno_page.add_item(anno)\ncanvas.add_item(anno_page)\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0004-canvas-size/","title":"Image and Canvas with Differing Dimensions","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0004-canvas-size/ JSON-LD: https://iiif.io/api/cookbook/recipe/0004-canvas-size/manifest.json"},{"location":"recipes/0004-canvas-size/#method-1-using-the-set_hwd-helper","title":"Method 1 - Using the set_hwd
helper","text":"from iiif_prezi3 import Manifest, AnnotationPage, Annotation, ResourceItem, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0004-canvas-size\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\", label=\"Still image from an opera performance at Indiana University\")\ncanvas = manifest.make_canvas(id=f\"{base_url}/canvas/p1\")\nanno_body = ResourceItem(id=\"https://fixtures.iiif.io/video/indiana/donizetti-elixir/act1-thumbnail.png\",\n type=\"Image\",\n format=\"image/png\")\nanno_page = AnnotationPage(id=f\"{base_url}/page/p1/1\")\nanno = Annotation(id=f\"{base_url}/annotation/p0001-image\",\n motivation=\"painting\",\n body=anno_body,\n target=canvas.id)\n\nanno_body.set_hwd(height=360, width=640)\ncanvas.set_hwd(height=1080, width=1920)\n\nanno_page.add_item(anno)\ncanvas.add_item(anno_page)\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0005-image-service/","title":"Support Deep Viewing with Basic Use of a IIIF Image Service","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0005-image-service/ JSON-LD: https://iiif.io/api/cookbook/recipe/0005-image-service/manifest.json"},{"location":"recipes/0005-image-service/#method-1-using-the-make_canvas_from_iiif-helper","title":"Method 1 - Using the make_canvas_from_iiif
helper","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0005-image-service\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\", label=\"Picture of G\u00f6ttingen taken during the 2019 IIIF Conference\")\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/918ecd18c2592080851777620de9bcb5-gottingen\",\n id=f\"{base_url}/canvas/p1\",\n label=\"Canvas with a single IIIF image\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0006-text-language/","title":"Internationalization and Multi-language Values","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0006-text-language/ JSON-LD: https://iiif.io/api/cookbook/recipe/0006-text-language/manifest.json"},{"location":"recipes/0006-text-language/#method-1-construct-the-language-dictionaries-during-object-creation","title":"Method 1 - Construct the language dictionaries during object creation","text":"from iiif_prezi3 import Manifest, KeyValueString\n\nbase_url = \"https://iiif.io/api/cookbook/recipe/0006-text-language\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\",\n label={\"en\": [\"Whistler's Mother\"], \"fr\": [\"La M\u00e8re de Whistler\"]})\nmanifest.metadata = [\n KeyValueString(label={\"en\": [\"Creator\"], \"fr\": [\"Auteur\"]}, value=\"Whistler, James Abbott McNeill\"),\n KeyValueString(label={\"en\": [\"Subject\"], \"fr\": [\"Sujet\"]},\n value={\"en\": [\"McNeill Anna Matilda, mother of Whistler (1804-1881)\"],\n \"fr\": [\"McNeill Anna Matilda, m\u00e8re de Whistler (1804-1881)\"]})\n]\nmanifest.summary = {\"en\": [\"Arrangement in Grey and Black No. 1, also called Portrait of the Artist's Mother.\"],\n \"fr\": [\"Arrangement en gris et noir n\u00b01, also called Portrait de la m\u00e8re de l'artiste.\"]}\nmanifest.requiredStatement = KeyValueString(label={\"en\": [\"Held By\"], \"fr\": [\"D\u00e9tenu par\"]}, value=\"Mus\u00e9e d'Orsay, Paris, France\")\n\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/329817fc8a251a01c393f517d8a17d87-Whistlers_Mother\",\n id=f\"{base_url}/canvas/p1\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0007-string-formats/","title":"Embedding HTML in descriptive properties","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0007-string-formats/ JSON-LD: https://iiif.io/api/cookbook/recipe/0007-string-formats/manifest.json"},{"location":"recipes/0007-string-formats/#method-1-building-the-object-directly-and-making-use-of-the-autolang-config","title":"Method 1 - Building the object directly and making use of the AutoLang config","text":"from iiif_prezi3 import Manifest, KeyValueString, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0007-string-formats\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\",\n label=\"Picture of G\u00f6ttingen taken during the 2019 IIIF Conference\",\n summary=\"<p>Picture taken by the <a href=\\\"https://github.com/glenrobson\\\">IIIF Technical Coordinator</a></p>\",\n rights=\"http://creativecommons.org/licenses/by-sa/3.0/\",\n requiredStatement=KeyValueString(label=\"Attribution\",\n value=\"<span>Glen Robson, IIIF Technical Coordinator. <a href=\\\"https://creativecommons.org/licenses/by-sa/3.0\\\">CC BY-SA 3.0</a> <img src=\\\"https://licensebuttons.net/l/by-sa/3.0/88x31.png\\\"/></span>\"),\n metadata=[KeyValueString(label=\"Author\", value={\"none\": [\"<span><a href='https://github.com/glenrobson'>Glen Robson</a></span>\"]})])\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/918ecd18c2592080851777620de9bcb5-gottingen\",\n id=f\"{base_url}/canvas/p1\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0008-rights/","title":"Rights statement","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0008-rights/ JSON-LD: https://iiif.io/api/cookbook/recipe/0008-rights/manifest.json"},{"location":"recipes/0008-rights/#method-1-building-the-object-directly-and-making-use-of-the-autolang-config","title":"Method 1 - Building the object directly and making use of the AutoLang config","text":"from iiif_prezi3 import Manifest, KeyValueString, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0008-rights\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\",\n label=\"Picture of G\u00f6ttingen taken during the 2019 IIIF Conference\",\n summary=\"<p>Picture taken by the <a href=\\\"https://github.com/glenrobson\\\">IIIF Technical Coordinator</a></p>\",\n rights=\"http://creativecommons.org/licenses/by-sa/3.0/\",\n requiredStatement=KeyValueString(label=\"Attribution\",\n value=\"<span>Glen Robson, IIIF Technical Coordinator. <a href=\\\"https://creativecommons.org/licenses/by-sa/3.0\\\">CC BY-SA 3.0</a> <a href=\\\"https://creativecommons.org/licenses/by-sa/3.0\\\" title=\\\"CC BY-SA 3.0\\\"><img src=\\\"https://licensebuttons.net/l/by-sa/3.0/88x31.png\\\"/></a></span>\")\n )\n\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/918ecd18c2592080851777620de9bcb5-gottingen\",\n id=f\"{base_url}/canvas/p1\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0009-book-1/","title":"Simple Manifest - Book","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0009-book-1/ JSON-LD: https://iiif.io/api/cookbook/recipe/0009-book-1/manifest.json"},{"location":"recipes/0009-book-1/#method-1-setting-the-behavior-property-during-object-construction","title":"Method 1 - Setting the behavior
property during object construction","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0009-book-1\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\",\n label=\"Simple Manifest - Book\",\n behavior=[\"paged\"])\ncanvas1 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f18\",\n id=f\"{base_url}/canvas/p1\",\n label=\"Blank page\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\ncanvas2 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f19\",\n id=f\"{base_url}/canvas/p2\",\n label=\"Frontispiece\",\n anno_id=f\"{base_url}/annotation/p0002-image\",\n anno_page_id=f\"{base_url}/page/p2/1\")\n\ncanvas3 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f20\",\n id=f\"{base_url}/canvas/p3\",\n label=\"Title page\",\n anno_id=f\"{base_url}/annotation/p0003-image\",\n anno_page_id=f\"{base_url}/page/p3/1\")\n\ncanvas4 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f21\",\n id=f\"{base_url}/canvas/p4\",\n label=\"Blank page\",\n anno_id=f\"{base_url}/annotation/p0004-image\",\n anno_page_id=f\"{base_url}/page/p4/1\")\n\ncanvas5 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f22\",\n id=f\"{base_url}/canvas/p5\",\n label=\"Bookplate\",\n anno_id=f\"{base_url}/annotation/p0005-image\",\n anno_page_id=f\"{base_url}/page/p5/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0010-book-2-viewing-direction/","title":"Viewing direction and Its Effect on Navigation","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0010-book-2-viewing-direction/ JSON-LD Example 1: https://iiif.io/api/cookbook/recipe/0010-book-2-viewing-direction/manifest-rtl.json JSON-LD Example 2: https://iiif.io/api/cookbook/recipe/0010-book-2-viewing-direction/manifest-ttb.json"},{"location":"recipes/0010-book-2-viewing-direction/#method-1-setting-the-viewingdirection-property-during-object-construction","title":"Method 1 - Setting the viewingDirection
property during object construction","text":""},{"location":"recipes/0010-book-2-viewing-direction/#example-1","title":"Example 1","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0010-book-2-viewing-direction\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest-rtl.json\",\n label=\"Book with Right-to-Left Viewing Direction\",\n summary=\"Playbill for \\\"Akiba gongen kaisen-banashi,\\\" \\\"Futatsu ch\u014dch\u014d kuruwa nikki\\\" and \\\"Godairiki koi no f\u016bjime\\\" performed at the Chikugo Theater in Osaka from the fifth month of Kaei 2 (May, 1849); main actors: Gad\u014d Kataoka II, Ebiz\u014d Ichikawa VI, Kit\u014d Sawamura II, Daigor\u014d Mimasu IV and Karoku Nakamura I; on front cover: producer Mominosuke Ichikawa's crest.\",\n viewingDirection=\"right-to-left\")\n\ncanvas1 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/4f92cceb12dd53b52433425ce44308c7-ucla_bib1987273_no001_rs_001\",\n id=f\"{base_url}/canvas/p1\",\n label=\"front cover\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\ncanvas2 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/4f92cceb12dd53b52433425ce44308c7-ucla_bib1987273_no001_rs_002\",\n id=f\"{base_url}/canvas/p2\",\n label=\"pages 1\u20132\",\n anno_id=f\"{base_url}/annotation/p0002-image\",\n anno_page_id=f\"{base_url}/page/p2/1\")\n\ncanvas3 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/4f92cceb12dd53b52433425ce44308c7-ucla_bib1987273_no001_rs_003\",\n id=f\"{base_url}/canvas/p3\",\n label=\"pages 3\u20134\",\n anno_id=f\"{base_url}/annotation/p0003-image\",\n anno_page_id=f\"{base_url}/page/p3/1\")\n\ncanvas4 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/4f92cceb12dd53b52433425ce44308c7-ucla_bib1987273_no001_rs_004\",\n id=f\"{base_url}/canvas/p4\",\n label=\"pages 5\u20136\",\n anno_id=f\"{base_url}/annotation/p0004-image\",\n anno_page_id=f\"{base_url}/page/p4/1\")\n\ncanvas5 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/4f92cceb12dd53b52433425ce44308c7-ucla_bib1987273_no001_rs_005\",\n id=f\"{base_url}/canvas/p5\",\n label=\"back cover\",\n anno_id=f\"{base_url}/annotation/p0005-image\",\n anno_page_id=f\"{base_url}/page/p5/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0010-book-2-viewing-direction/#example-2","title":"Example 2","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0010-book-2-viewing-direction\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest-ttb.json\",\n label=\"Diary with Top-to-Bottom Viewing Direction\",\n summary=\"William Lewis Sachtleben was an American long-distance cyclist who rode across Asia from Istanbul to Peking in 1891 to 1892 with Thomas Gaskell Allen Jr., his classmate from Washington University. This was part of a longer journey that began the day after they had graduated from college, when they travelled to New York and on to Liverpool; in all they travelled 15,044 miles by bicycle, 'the longest continuous land journey ever made around the world' as reported in their book <cite>Across Asia on a bicycle</cite> (1895). Sachtleben documented his travels with photographs and diaries, the latter of which he numbered sequentially. The diary of notebook 'No. 10' covers a portion of their journey through the Armenian area of Turkey from April 12 to May 9 (there is a 2-page reading list at the end). During this time they rode from Ankara (Angora in the diary) to Sivas, where they stayed for ten days while Allen had a bout of typhoid fever, and the first half of a ten-day excursion to Merzifon (Mersovan in the diary), taken by Sachtleben to give Allen additional time to recover.\",\n viewingDirection=\"top-to-bottom\")\ncanvas1 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/9ee11092dfd2782634f5e8e2c87c16d5-uclamss_1841_diary_07_02\",\n id=f\"{base_url}/canvas/v1\",\n label=\"image 1\",\n anno_id=f\"{base_url}/annotation/v0001-image\",\n anno_page_id=f\"{base_url}/page/v1/1\")\n\ncanvas2 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/9ee11092dfd2782634f5e8e2c87c16d5-uclamss_1841_diary_07_03\",\n id=f\"{base_url}/canvas/v2\",\n label=\"image 2\",\n anno_id=f\"{base_url}/annotation/v0002-image\",\n anno_page_id=f\"{base_url}/page/v2/1\")\n\ncanvas3 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/9ee11092dfd2782634f5e8e2c87c16d5-uclamss_1841_diary_07_04\",\n id=f\"{base_url}/canvas/v3\",\n label=\"image 3\",\n anno_id=f\"{base_url}/annotation/v0003-image\",\n anno_page_id=f\"{base_url}/page/v3/1\")\n\ncanvas4 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/9ee11092dfd2782634f5e8e2c87c16d5-uclamss_1841_diary_07_05\",\n id=f\"{base_url}/canvas/v4\",\n label=\"image 4\",\n anno_id=f\"{base_url}/annotation/v0004-image\",\n anno_page_id=f\"{base_url}/page/v4/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0011-book-3-behavior/","title":"Book 'behavior' Variations (continuous, individuals)","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0011-book-3-behavior/ JSON-LD Use Case 1: https://iiif.io/api/cookbook/recipe/0011-book-3-behavior/manifest-continuous.json JSON-LD Use Case 2: https://iiif.io/api/cookbook/recipe/0011-book-3-behavior/manifest-individuals.json"},{"location":"recipes/0011-book-3-behavior/#method-1-setting-the-behavior-property-during-object-construction","title":"Method 1 - Setting the behavior
property during object construction","text":""},{"location":"recipes/0011-book-3-behavior/#use-case-1","title":"Use Case 1","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0011-book-3-behavior\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest-continuous.json\",\n label={\"gez\": [\"Ms. 21 M\u0101zemur\u0101 D\u0101wit, Asmat [\u1218\u12dd\u1219\u1228 \u12f3\u12ca\u1275]\"]},\n behavior=[\"continuous\"])\ncanvas1 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/8c169124171e6b2253b698a22a938f07-21198-zz001hbmd9_1300412_master\",\n id=f\"{base_url}/canvas/s1\",\n label=\"Section 1 [Recto]\",\n anno_id=f\"{base_url}/annotation/s0001-image\",\n anno_page_id=f\"{base_url}/page/s1/1\")\n\ncanvas2 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/8c169124171e6b2253b698a22a938f07-21198-zz001hbmft_1300418_master\",\n id=f\"{base_url}/canvas/s2\",\n label=\"Section 2 [Recto]\",\n anno_id=f\"{base_url}/annotation/s0002-image\",\n anno_page_id=f\"{base_url}/page/s2/1\")\n\ncanvas3 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/8c169124171e6b2253b698a22a938f07-21198-zz001hbmgb_1300426_master\",\n id=f\"{base_url}/canvas/s3\",\n label=\"Section 3 [Recto]\",\n anno_id=f\"{base_url}/annotation/s0003-image\",\n anno_page_id=f\"{base_url}/page/s3/1\")\n\ncanvas4 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/8c169124171e6b2253b698a22a938f07-21198-zz001hbmhv_1300436_master\",\n id=f\"{base_url}/canvas/s4\",\n label=\"Section 4 [Recto]\",\n anno_id=f\"{base_url}/annotation/s0004-image\",\n anno_page_id=f\"{base_url}/page/s4/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0011-book-3-behavior/#use-case-2","title":"Use Case 2","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0011-book-3-behavior\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest-individuals.json\",\n label={\"ca\": [\"[Conoximent de las orines] Ihesus, Ihesus. En nom de Deu et dela beneyeta sa mare e de tots los angels i archangels e de tots los sants e santes de paradis yo micer Johannes comense aquest libre de reseptes en l\u2019ayn Mi 466.\"]},\n behavior=[\"individuals\"])\n\ncanvas1 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/85a96c630f077e6ac6cb984f1b752bbf-0-21198-zz00022840-1-master\",\n id=f\"{base_url}/canvas/v1\",\n label=\"inside cover; 1r\",\n anno_id=f\"{base_url}/annotation/v0001-image\",\n anno_page_id=f\"{base_url}/page/v1/1\")\n\ncanvas2 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/85a96c630f077e6ac6cb984f1b752bbf-1-21198-zz00022882-1-master\",\n id=f\"{base_url}/canvas/v2\",\n label=\"2v, 3r\",\n anno_id=f\"{base_url}/annotation/v0002-image\",\n anno_page_id=f\"{base_url}/page/v2/1\")\n\ncanvas3 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/85a96c630f077e6ac6cb984f1b752bbf-2-21198-zz000228b3-1-master\",\n id=f\"{base_url}/canvas/v3\",\n label=\"3v, 4r\",\n anno_id=f\"{base_url}/annotation/v0003-image\",\n anno_page_id=f\"{base_url}/page/v3/1\")\n\ncanvas4 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/85a96c630f077e6ac6cb984f1b752bbf-3-21198-zz000228d4-1-master\",\n id=f\"{base_url}/canvas/v4\",\n label=\"4v, 5r\",\n anno_id=f\"{base_url}/annotation/v0004-image\",\n anno_page_id=f\"{base_url}/page/v4/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0014-accompanyingcanvas/","title":"\"Audio Presentation with Accompanying Image\"","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0014-accompanyingcanvas/ JSON-LD: https://iiif.io/api/cookbook/recipe/0014-accompanyingcanvas/manifest.json"},{"location":"recipes/0014-accompanyingcanvas/#method-1-use-accompanyingcanvas-and-add_item-helper","title":"Method 1 - Use AccompanyingCanvas and add_item() helper","text":"from iiif_prezi3 import Manifest, ResourceItem, AnnotationPage, Annotation, config, AccompanyingCanvas\n\nbase_url = \"https://iiif.io/api/cookbook/recipe/0014-accompanyingcanvas\"\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\naccompanying_canvas = AccompanyingCanvas(\n id=f\"{base_url}/canvas/accompanying\",\n label=\"First page of score for Gustav Mahler, Symphony No. 3\",\n height=998,\n width=772,\n)\nmanifest = Manifest(\n id=f\"{base_url}/manifest.json\",\n label=\"Partial audio recording of Gustav Mahler's _Symphony No. 3_\",\n)\nac_anno_body = ResourceItem(\n id=\"https://iiif.io/api/image/3.0/example/reference/4b45bba3ea612ee46f5371ce84dbcd89-mahler-0/full/,998/0/default.jpg\",\n type=\"Image\",\n format=\"image/jpeg\",\n height=998,\n width=772,\n)\nac_anno_body.make_service(\n id=\"https://iiif.io/api/image/3.0/example/reference/4b45bba3ea612ee46f5371ce84dbcd89-mahler-0\",\n type=\"ImageService3\",\n profile=\"level1\"\n)\nac_anno_page = AnnotationPage(\n id=f\"{base_url}/canvas/accompanying/annotation/page\"\n)\nac_anno = Annotation(\n id=f\"{base_url}/canvas/accompanying/annotation/image\",\n motivation=\"painting\",\n body=ac_anno_body,\n target=f\"{base_url}/canvas/accompanying\"\n)\nac_anno_page.add_item(ac_anno)\naccompanying_canvas.add_item(ac_anno_page)\ncanvas = manifest.make_canvas(\n id=f\"{base_url}/canvas/p1\",\n label=\"Gustav Mahler, Symphony No. 3, CD 1\",\n duration=1985.024,\n accompanyingCanvas=accompanying_canvas\n)\nanno_body = ResourceItem(\n id=\"https://fixtures.iiif.io/audio/indiana/mahler-symphony-3/CD1/medium/128Kbps.mp4\",\n type=\"Sound\",\n format=\"video/mp4\",\n duration=1985.024,\n)\nanno_page = AnnotationPage(\n id=f\"{base_url}/canvas/page/p1\"\n)\nanno = Annotation(\n id=f\"{base_url}/canvas/page/annotation/segment1-audio\",\n motivation=\"painting\",\n body=anno_body,\n target=canvas.id\n)\nanno_page.add_item(anno)\ncanvas.add_item(anno_page)\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0015-start/","title":"Begin playback at a specific point - Time-based media","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0015-start/ JSON-LD: https://iiif.io/api/cookbook/recipe/0015-start/manifest.json"},{"location":"recipes/0015-start/#method-1-building-the-start-structure-using-the-specificresource-class","title":"Method 1 - Building the start
structure using the SpecificResource
class","text":"from iiif_prezi3 import Manifest, KeyValueString, ResourceItem, AnnotationPage, Annotation, SpecificResource, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0015-start\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\",\n label=\"Video of a 30-minute digital clock\",\n rights=\"http://creativecommons.org/licenses/by/3.0/\",\n requiredStatement=KeyValueString(label=\"Attribution\",\n value=\"<span>The video was created by <a href='https://www.youtube.com/watch?v=Lsq0FiXjGHg'>DrLex1</a> and was released using a <a href='https://creativecommons.org/licenses/by/3.0/'>Creative Commons Attribution license</a></span>\")\n )\n\ncanvas = manifest.make_canvas(id=f\"{base_url}/canvas/segment1\", duration=1801.055)\nanno_body = ResourceItem(id=\"https://fixtures.iiif.io/video/indiana/30-minute-clock/medium/30-minute-clock.mp4\",\n type=\"Video\",\n format=\"video/mp4\",\n duration=1801.055)\nanno_page = AnnotationPage(id=f\"{base_url}/annotation/segment1/page\")\nanno = Annotation(id=f\"{base_url}/annotation/segment1-video\",\n motivation=\"painting\",\n body=anno_body,\n target=canvas.id)\n\nanno_page.add_item(anno)\ncanvas.add_item(anno_page)\n\nmanifest.start = SpecificResource(id=f\"{base_url}/canvas-start/segment1\",\n source=canvas.id,\n selector={\"type\": \"PointSelector\", \"t\": 120.5})\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0017-transcription-av/","title":"Providing Access to Transcript Files of A/V Content","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0017-transcription-av/ JSON-LD: https://iiif.io/api/cookbook/recipe/0017-transcription-av/manifest.json"},{"location":"recipes/0017-transcription-av/#method-1-building-the-rendering-structure-using-the-externalitem-class","title":"Method 1 - Building the rendering
structure using the ExternalItem
class","text":"from iiif_prezi3 import Manifest, ExternalItem, ResourceItem, AnnotationPage, Annotation, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0017-transcription-av\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\",\n label=\"Volleyball for Boys\")\n\ncanvas = manifest.make_canvas(id=f\"{base_url}/canvas\")\nanno_body = ResourceItem(id=\"https://fixtures.iiif.io/video/indiana/volleyball/high/volleyball-for-boys.mp4\",\n type=\"Video\",\n format=\"video/mp4\")\nanno_page = AnnotationPage(id=f\"{base_url}/canvas/page\")\nanno = Annotation(id=f\"{base_url}/canvas/page/annotation\",\n motivation=\"painting\",\n body=anno_body,\n target=canvas.id)\n\nhwd = {\"height\": 1080, \"width\": 1920, \"duration\": 662.037}\nanno_body.set_hwd(**hwd)\ncanvas.set_hwd(**hwd)\n\nanno_page.add_item(anno)\ncanvas.add_item(anno_page)\n\nrendering = ExternalItem(id=\"https://fixtures.iiif.io/video/indiana/volleyball/volleyball.txt\",\n type=\"Text\",\n label=\"Transcript\",\n format=\"text/plain\")\n\ncanvas.rendering = [rendering]\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0019-html-in-annotations/","title":"HTML in Annotations","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0019-html-in-annotations/ JSON-LD: https://iiif.io/api/cookbook/recipe/0019-html-in-annotations/manifest.json"},{"location":"recipes/0019-html-in-annotations/#method-1-construct-an-annotation-using-the-make_annotation-helper-and-a-dictionary-of-the-body-properties","title":"Method 1 - Construct an Annotation using the make_annotation
helper and a dictionary of the body
properties","text":"from iiif_prezi3 import Manifest\n\nbase_url = \"https://iiif.io/api/cookbook/recipe/0019-html-in-annotations\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\",\n label={\"en\": [\"Picture of G\u00f6ttingen taken during the 2019 IIIF Conference\"]})\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/918ecd18c2592080851777620de9bcb5-gottingen\",\n id=f\"{base_url}/canvas-1\",\n anno_id=f\"{base_url}/canvas-1/annopage-1/anno-1\",\n anno_page_id=f\"{base_url}/canvas-1/annopage-1\")\n\nanno = canvas.make_annotation(id=f\"{base_url}/canvas-1/annopage-2/anno-1\",\n motivation=\"commenting\",\n body={\"type\": \"TextualBody\",\n \"language\": \"de\",\n \"format\": \"text/html\",\n \"value\": \"<p>G\u00f6ttinger Marktplatz mit <a href='https://de.wikipedia.org/wiki/G%C3%A4nseliesel-Brunnen_(G%C3%B6ttingen)'>G\u00e4nseliesel Brunnen <img src='https://en.wikipedia.org/static/images/project-logos/enwiki.png' alt='Wikipedia logo'></a></p>\"},\n target=canvas.id,\n anno_page_id=f\"{base_url}/canvas-1/annopage-2\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0021-tagging/","title":"Simple Annotation \u2014 Tagging","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0021-tagging/ JSON-LD: https://iiif.io/api/cookbook/recipe/0021-tagging/manifest.json"},{"location":"recipes/0021-tagging/#method-1-construct-an-annotation-using-the-make_annotation-helper-and-a-dictionary-of-the-body-properties","title":"Method 1 - Construct an Annotation using the make_annotation
helper and a dictionary of the body
properties","text":"from iiif_prezi3 import Manifest\n\nbase_url = \"https://iiif.io/api/cookbook/recipe/0021-tagging\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\",\n label={\"en\": [\"Picture of G\u00f6ttingen taken during the 2019 IIIF Conference\"]})\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/918ecd18c2592080851777620de9bcb5-gottingen\",\n id=f\"{base_url}/canvas/p1\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\nanno = canvas.make_annotation(id=f\"{base_url}/annotation/p0002-tag\",\n motivation=\"tagging\",\n body={\"type\": \"TextualBody\",\n \"language\": \"de\",\n \"format\": \"text/plain\",\n \"value\": \"G\u00e4nseliesel-Brunnen\"},\n target=canvas.id + \"#xywh=265,661,1260,1239\",\n anno_page_id=f\"{base_url}/page/p2/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0047-homepage/","title":"Linking to Web Page of an Object","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0047-homepage/ JSON-LD: https://iiif.io/api/cookbook/recipe/0047-homepage/manifest.json"},{"location":"recipes/0047-homepage/#method-1-add-homepage-as-homepageitem","title":"Method 1 - Add Homepage as HomepageItem","text":"from iiif_prezi3 import Manifest, ResourceItem, AnnotationPage, Annotation, config, HomepageItem\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"none\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0047-homepage\"\n\nhomepage = HomepageItem(\n id=\"https://www.getty.edu/art/collection/object/103RQQ\",\n type=\"Text\",\n label={\"en\": [\"Home page at the Getty Museum Collection\"]},\n format=\"text/html\",\n language=\"en\",\n)\nmanifest = Manifest(\n id=f\"{base_url}/manifest.json\",\n label=\"Laoc\u00f6on\",\n homepage=homepage,\n)\ncanvas = manifest.make_canvas(\n id=f\"{base_url}/canvas/1\",\n label=\"Front\"\n)\nanno_body = ResourceItem(\n id=\"https://iiif.io/api/image/3.0/example/reference/28473c77da3deebe4375c3a50572d9d3-laocoon/full/!500,500/0/default.jpg\",\n type=\"Image\",\n format=\"image/jpeg\"\n)\nanno_body.make_service(\n id=\"https://iiif.io/api/image/3.0/example/reference/28473c77da3deebe4375c3a50572d9d3-laocoon\",\n type=\"ImageService3\",\n profile=\"level1\"\n)\nanno_page = AnnotationPage(\n id=f\"{base_url}/canvas/1/page/1\"\n)\nhw = {\"height\": 3000, \"width\": 2315}\nanno_body.set_hwd(**hw)\ncanvas.set_hwd(**hw)\nanno = Annotation(\n id=f\"{base_url}/canvas/1/page/1/annotation/1\",\n motivation=\"painting\",\n body=anno_body,\n target=canvas.id\n)\nanno_page.add_item(anno)\ncanvas.add_item(anno_page)\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0074-multiple-language-captions/","title":"Using Caption and Subtitle Files in Multiple Languages with Video Content","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0074-multiple-language-captions/ JSON-LD: https://iiif.io/api/cookbook/recipe/0074-multiple-language-captions/manifest.json"},{"location":"recipes/0074-multiple-language-captions/#method-1-construct-supplementing-annotation-using-the-make_annotation-helper-and-a-dictionary-of-the-body-properties","title":"Method 1 - Construct Supplementing Annotation Using the make_annotation
helper and a dictionary of the body
properties","text":"from iiif_prezi3 import Manifest, ResourceItem, AnnotationPage, Annotation, KeyValueString, config, Choice\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0074-multiple-language-captions\"\n\nmanifest = Manifest(\n id=f\"{base_url}/manifest.json\",\n label=\"For ladies. French models\",\n rights=\"http://rightsstatements.org/vocab/InC/1.0/\",\n requiredStatement=KeyValueString(label=\"Rights\", value=\"All rights reserved Cinecitt\u00e0 Luce spa\")\n)\nmanifest.add_label(language=\"it\", value=\"Per voi signore. Modelli francesi\")\n\ncanvas = manifest.make_canvas(\n id=f\"{base_url}/canvas\"\n)\nvideo_resource = ResourceItem(\n id=\"https://fixtures.iiif.io/video/europeana/Per_voi_signore_Modelli_francesi.mp4\",\n type=\"Video\",\n format=\"video/mp4\"\n)\nvideo_hwd = {\"height\": 384, \"width\": 288, \"duration\": 65.0}\nvideo_resource.set_hwd(**video_hwd)\ncanvas.set_hwd(**video_hwd)\npainting_annotation = Annotation(\n id=f\"{base_url}/canvas/page/annotation\",\n motivation=\"painting\",\n body=video_resource,\n target=canvas.id\n)\nannotation_page = AnnotationPage(\n id=f\"{base_url}/canvas/page\"\n)\nannotation_page.add_item(painting_annotation)\ncanvas.add_item(annotation_page)\n\nitalian_captions = ResourceItem(\n id=f\"{base_url}/Per_voi_signore_Modelli_francesi_it.vtt\",\n type=\"Text\",\n format=\"text/vtt\",\n language=\"it\",\n)\nitalian_captions.add_label(language=\"it\", value=\"Sottotitoli in formato WebVTT\")\nenglish_captions = ResourceItem(\n id=f\"{base_url}/Per_voi_signore_Modelli_francesi_en.vtt\",\n type=\"Text\",\n format=\"text/vtt\",\n language=\"en\"\n)\nenglish_captions.add_label(language=\"en\", value=\"Captions in WebVTT format\")\nchoice = Choice(\n items=[english_captions, italian_captions]\n)\n\ncaption_annotation = canvas.make_annotation(\n id=f\"{base_url}/manifest.json/subtitles_captions-files-vtt\",\n motivation=\"supplementing\",\n body=choice,\n target=canvas.id,\n anno_page_id=f\"{base_url}/manifest.json/anno/page/1\"\n)\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0118-multivalue/","title":"Displaying Multiple Values with Language Maps","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0118_multivalue/ JSON-LD: https://iiif.io/api/cookbook/recipe/0118_multivalue/manifest.json"},{"location":"recipes/0118-multivalue/#method-1-use-a-keyvaluestring-object-and-a-dictionary-to-create-language-maps","title":"Method 1 - Use a KeyValueString
object and a dictionary to create language maps.","text":"from iiif_prezi3 import Manifest, KeyValueString\n\nbase_url = \"https://iiif.io/api/cookbook/recipe/0118-multivalue\"\n\nmanifest = Manifest(id=\"https://iiif.io/api/cookbook/recipe/0118_multivalue/manifest.json\",\n label={\"fr\": [\"Arrangement en gris et noir no 1\"]})\nmanifest.metadata = [\n KeyValueString(label={\"en\": [\"Alternative titles\"]},\n value={\"en\": [\"Whistler's Mother\", \"Arrangement in Grey and Black No. 1\"],\n \"fr\": [\"Portrait de la m\u00e8re de l'artiste\", \"La M\u00e8re de Whistler\"]})\n]\nmanifest.summary = {\"en\": [\"A painting in oil on canvas created by the American-born painter James McNeill Whistler, in 1871.\"]}\n\ncanvas = manifest.make_canvas(id=\"https://iiif.io/api/cookbook/recipe/0118_multivalue/canvas/1\", height=991, width=1114)\nanno_page = canvas.add_image(image_url=\"https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Whistlers_Mother_high_res.jpg/1114px-Whistlers_Mother_high_res.jpg\",\n anno_page_id=\"https://iiif.io/api/cookbook/recipe/0118_multivalue/canvas/1/page/1\",\n anno_id=\"https://iiif.io/api/cookbook/recipe/0118_multivalue/canvas/1/page/1/annotation/1\",\n format=\"image/jpeg\",\n )\n\ncanvas.items[0].items[0].id = \"https://iiif.io/api/cookbook/recipe/0118_multivalue/canvas/1/page/1/annotation/1\"\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0230-navdate/","title":"Navigation by Chronology","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0230-navdate/ JSON-LD Example 1 - 1986 Map: https://iiif.io/api/cookbook/recipe/0230-navdate/navdate_map_2-manifest.json JSON-LD Example 2 - 1987 Map: https://iiif.io/api/cookbook/recipe/0230-navdate/navdate_map_1-manifest.json JSON-LD Example 3 - Collection: https://iiif.io/api/cookbook/recipe/0230-navdate/navdate-collection.json"},{"location":"recipes/0230-navdate/#method-1-setting-the-navdate-property-during-object-construction-using-a-datetime-object","title":"Method 1 - Setting the navDate
property during object construction using a datetime
object","text":""},{"location":"recipes/0230-navdate/#example-1-1986-map","title":"Example 1 - 1986 Map","text":"from iiif_prezi3 import Manifest, config\nfrom datetime import datetime, timezone\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0230-navdate\"\n\n# n.b: You MUST set `tzinfo` as the Prezi3 Specification requires a timezone, and the default `datetime` does not have one.\nmanifest = Manifest(id=f\"{base_url}/navdate_map_2-manifest.json\",\n label=\"1986 Chesapeake and Ohio Canal, Washington, D.C., Maryland, West Virginia, official map and guide\",\n navDate=datetime(1986, 1, 1, tzinfo=timezone.utc))\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-87691274-1986\",\n id=f\"{base_url}/canvas/p1\",\n label=\"1986 Map, recto and verso, with a date of publication\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\n# This is a workaround for an inconsistency in the Cookbook JSON - see https://github.com/IIIF/cookbook-recipes/issues/376\ncanvas.items[0].items[0].body.service[0].id = \"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-87691274-1986/\"\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0230-navdate/#example-2-1987-map","title":"Example 2 - 1987 Map","text":"from iiif_prezi3 import Manifest, config\nfrom datetime import datetime, timezone\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0230-navdate\"\n\n# n.b: You MUST set `tzinfo` as the Prezi3 Specification requires a timezone, and the default `datetime` does not have one.\nmanifest = Manifest(id=f\"{base_url}/navdate_map_1-manifest.json\",\n label=\"1987 Chesapeake and Ohio Canal, Washington, D.C., Maryland, West Virginia, official map and guide\",\n navDate=datetime(1987, 1, 1, tzinfo=timezone.utc))\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-88695674\",\n id=f\"{base_url}/canvas/p1\",\n label=\"1987 Map, recto and verso, with a date of publication\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\n# This is a workaround for an inconsistency in the Cookbook JSON - see https://github.com/IIIF/cookbook-recipes/issues/376\ncanvas.items[0].items[0].body.service[0].id = \"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-88695674/\"\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0230-navdate/#example-3-collection","title":"Example 3 - Collection","text":"Here we can make use of the fact that iiif-prezi3
will automatically turn a Manifest into a reference when it is added to a Collection object.
from iiif_prezi3 import Collection, Manifest, ResourceItem, config\nfrom datetime import datetime, timezone\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0230-navdate\"\n\n# n.b: You MUST set `tzinfo` as the Prezi3 Specification requires a timezone, and the default `datetime` does not have one.\nmanifest1986 = Manifest(id=f\"{base_url}/navdate_map_2-manifest.json\",\n label=\"1986 Chesapeake and Ohio Canal, Washington, D.C., Maryland, West Virginia, official map and guide\",\n navDate=datetime(1986, 1, 1, tzinfo=timezone.utc))\ncanvas1986 = manifest1986.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-87691274-1986\",\n id=f\"{base_url}/canvas/p1\",\n label=\"1986 Map, recto and verso, with a date of publication\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\nmanifest1987 = Manifest(id=f\"{base_url}/navdate_map_1-manifest.json\",\n label=\"1987 Chesapeake and Ohio Canal, Washington, D.C., Maryland, West Virginia, official map and guide\",\n navDate=datetime(1987, 1, 1, tzinfo=timezone.utc))\ncanvas1987 = manifest1987.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-88695674\",\n id=f\"{base_url}/canvas/p1\",\n label=\"1987 Map, recto and verso, with a date of publication\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\ncollection = Collection(id=f\"{base_url}/navdate-collection.json\",\n label=\"Chesapeake and Ohio Canal map and guide pamphlets\")\nthumbnail = ResourceItem(id=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-88695674/full/max/0/default.jpg\",\n type=\"Image\",\n format=\"image/jpeg\",\n height=300,\n width=221)\nthumbnail.make_service(id=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-88695674\",\n type=\"ImageService3\",\n profile=\"level1\")\ncollection.thumbnail = [thumbnail]\n\ncollection.add_item(manifest1986)\ncollection.add_item(manifest1987)\ncollection.items[0].navDate = manifest1986.navDate\ncollection.items[1].navDate = manifest1987.navDate\n\nprint(collection.json(indent=2))\n
"},{"location":"recipes/0230-navdate/#method-2-setting-the-navdate-property-with-a-string","title":"Method 2 - Setting the navDate
property with a string","text":""},{"location":"recipes/0230-navdate/#example-1-1986-map_1","title":"Example 1 - 1986 Map","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0230-navdate\"\n\nmanifest = Manifest(id=f\"{base_url}/navdate_map_2-manifest.json\",\n label=\"1986 Chesapeake and Ohio Canal, Washington, D.C., Maryland, West Virginia, official map and guide\",\n navDate=\"1986-01-01T00:00:00Z\")\n\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-87691274-1986\",\n id=f\"{base_url}/canvas/p1\",\n label=\"1986 Map, recto and verso, with a date of publication\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\n# This is a workaround for an inconsistency in the Cookbook JSON - see https://github.com/IIIF/cookbook-recipes/issues/376\ncanvas.items[0].items[0].body.service[0].id = \"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-87691274-1986/\"\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0230-navdate/#example-2-1987-map_1","title":"Example 2 - 1987 Map","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0230-navdate\"\n\nmanifest = Manifest(id=f\"{base_url}/navdate_map_1-manifest.json\",\n label=\"1987 Chesapeake and Ohio Canal, Washington, D.C., Maryland, West Virginia, official map and guide\",\n navDate=\"1987-01-01T00:00:00Z\")\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-88695674\",\n id=f\"{base_url}/canvas/p1\",\n label=\"1987 Map, recto and verso, with a date of publication\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\n# This is a workaround for an inconsistency in the Cookbook JSON - see https://github.com/IIIF/cookbook-recipes/issues/376\ncanvas.items[0].items[0].body.service[0].id = \"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-88695674/\"\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0230-navdate/#example-3-collection_1","title":"Example 3 - Collection","text":"To show the different possible approaches, here we will build the Collection object manually using the ManifestRef
class.
from iiif_prezi3 import Collection, ManifestRef, ResourceItem, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0230-navdate\"\n\ncollection = Collection(id=f\"{base_url}/navdate-collection.json\",\n label=\"Chesapeake and Ohio Canal map and guide pamphlets\")\nthumbnail = ResourceItem(id=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-88695674/full/max/0/default.jpg\",\n type=\"Image\",\n format=\"image/jpeg\",\n height=300,\n width=221)\nthumbnail.make_service(id=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-88695674\",\n type=\"ImageService3\",\n profile=\"level1\")\ncollection.thumbnail = [thumbnail]\n\nmanifest1986 = ManifestRef(id=f\"{base_url}/navdate_map_2-manifest.json\",\n type=\"Manifest\",\n label=\"1986 Chesapeake and Ohio Canal, Washington, D.C., Maryland, West Virginia, official map and guide\",\n navDate=\"1986-01-01T00:00:00+00:00\")\n\nmanifest1987 = ManifestRef(id=f\"{base_url}/navdate_map_1-manifest.json\",\n type=\"Manifest\",\n label=\"1987 Chesapeake and Ohio Canal, Washington, D.C., Maryland, West Virginia, official map and guide\",\n navDate=\"1987-01-01T00:00:00+00:00\")\n\ncollection.add_item(manifest1986)\ncollection.add_item(manifest1987)\n\nprint(collection.json(indent=2))\n
"},{"location":"recipes/0261-non-rectangular-commenting/","title":"Annotation with a Non-Rectangular Polygon","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0261-non-rectangular-commenting/ JSON-LD: https://iiif.io/api/cookbook/recipe/0261-non-rectangular-commenting/manifest.json"},{"location":"recipes/0261-non-rectangular-commenting/#method-1-","title":"Method 1 -","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0261-non-rectangular-commenting\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\", label=\"Picture of G\u00f6ttingen taken during the 2019 IIIF Conference\")\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/918ecd18c2592080851777620de9bcb5-gottingen\",\n id=f\"{base_url}/canvas/p1\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\nanno = canvas.make_annotation(id=f\"{base_url}/annotation/p0002-svg\",\n motivation=\"tagging\",\n body={\"type\": \"TextualBody\",\n \"language\": \"de\",\n \"format\": \"text/plain\",\n \"value\": \"G\u00e4nseliesel-Brunnen\"},\n target={\"type\": \"SpecificResource\",\n \"source\": canvas.id,\n \"selector\": {\"type\": \"SvgSelector\",\n \"value\": \"<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'><g><path d='M270.000000,1900.000000 L1530.000000,1900.000000 L1530.000000,1610.000000 L1315.000000,1300.000000 L1200.000000,986.000000 L904.000000,661.000000 L600.000000,986.000000 L500.000000,1300.000000 L270,1630 L270.000000,1900.000000' /></g></svg>\"\n }\n },\n anno_page_id=f\"{base_url}/page/p2/1\")\n\nprint(manifest.json(indent=2))\n
"}]}
\ No newline at end of file
+{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"iiif-prezi3","text":"IIIF Presentation API 3 Python Library
"},{"location":"#installation","title":"Installation","text":""},{"location":"#pypi","title":"PyPI","text":"The easiest way to install the iiif-prezi3
library is directly from PyPI:
pip install iiif-prezi3\n
"},{"location":"#manual-installation","title":"Manual installation","text":"Alternatively, you can clone the repository and run setup.py
locally:
git clone https://github.com/iiif-prezi/iiif-prezi3.git\n
or git clone git@github.com:iiif-prezi/iiif-prezi3.git\n
followed by: cd iiif-prezi3\npython setup.py install\n
"},{"location":"#basic-usage","title":"Basic Usage","text":"You can now import the library or individual classes from within Python and start creating your IIIF Presentation 3 objects:
"},{"location":"#directly-creating-a-manifest","title":"Directly creating a Manifest","text":">>> from iiif_prezi3 import Manifest\n>>> m = Manifest(id=\"https://example.com/iiif/manifest.json\", label={\"en\":[\"Example Manifest\"]})\n>>> print(m.json(indent=2))\n{\n \"@context\": \"http://iiif.io/api/presentation/3/context.json\",\n \"id\": \"https://example.com/iiif/manifest.json\",\n \"type\": \"Manifest\",\n \"label\": {\n \"en\": [\n \"Example Manifest\"\n ]\n }\n}\n
"},{"location":"#importing-an-existing-iiif-manifest","title":"Importing an existing IIIF Manifest","text":"If you have an existing IIIF Presentation v3 Manifest, you can load it via the built-in json
module and create the objects:
>>> from iiif_prezi3 import Manifest\n>>> import json\n>>> manifest_json = json.load(open(\"example.json\"))\n>>> m = Manifest(**manifest_json)\n>>> print(m.json(indent=2))\n{\n \"@context\": \"http://iiif.io/api/presentation/3/context.json\",\n \"id\": \"https://iiif.io/api/cookbook/recipe/0003-mvm-video/manifest.json\",\n \"type\": \"Manifest\",\n \"label\": {\n \"en\": [\n \"Video Example 3\"\n ]\n },\n \"items\": [\n {\n \"id\": \"https://iiif.io/api/cookbook/recipe/0003-mvm-video/canvas\",\n \"type\": \"Canvas\",\n \"height\": 360,\n \"width\": 640,\n \"duration\": 572.034,\n \"items\": [\n {\n \"id\": \"https://iiif.io/api/cookbook/recipe/0003-mvm-video/canvas/page\",\n \"type\": \"AnnotationPage\",\n \"items\": [\n {\n \"id\": \"https://iiif.io/api/cookbook/recipe/0003-mvm-video/canvas/page/annotation\",\n \"type\": \"Annotation\",\n \"motivation\": \"painting\",\n \"body\": {\n \"id\": \"https://fixtures.iiif.io/video/indiana/lunchroom_manners/high/lunchroom_manners_1024kb.mp4\",\n \"type\": \"Video\",\n \"height\": 360,\n \"width\": 480,\n \"duration\": 572.034,\n \"format\": \"video/mp4\"\n },\n \"target\": \"https://iiif.io/api/cookbook/recipe/0003-mvm-video/canvas\"\n }\n ]\n }\n ]\n }\n ]\n}\n
"},{"location":"#extensions","title":"Extensions","text":"iiif-prezi3
includes the capability to load extensions to the IIIF Presentation schema (e.g navPlace) and modify the library's Python classes to include extra properties, validation, helper methods, etc.
Published extensions from the IIIF Registry of Extensions are included with the package, and can be loaded using the iiif_prezi3.load_bundled_extensions()
method.
Called without argument, this method will load all bundled extensions listed in the iiif_prezi3/config/extensions.json file. If you wish to only load selected extensions from those available bundled with the library, you can pass either the path to a JSON file, or a list of extension names as an argument to the function:
>>> import iiif_prezi3\n>>> iiif_prezi3.load_bundled_extensions(extensions=\"/path/to/chosen_extensions.json\")\n
>>> import iiif_prezi3\n>>> iiif_prezi3.load_bundled_extensions(extensions=['example_extension'])\n
Extensions work in much the same way as helper methods, and are monkeypatched into the relevant objects in the iiif_prezi3.skeleton
class, from which everything is loaded. For a simple example, please see the extensions/example_extension.py
file, and the documentation on writing a helper method.
"},{"location":"#local-development","title":"Local Development","text":"For developing iiif-prezi3
locally, clone the repo and then install it and the development dependencies using pip's \"editable mode\":
git clone git@github.com:iiif-prezi/iiif-prezi3.git\ncd iiif-prezi3\npip install -e .[dev]\n
"},{"location":"#running-tests","title":"Running Tests","text":"Tests (including linting) can be run using tox. First, install tox with pip install tox
, then type tox
.
"},{"location":"#versioning","title":"Versioning","text":"iiif-prezi3
broadly follows Semantic Versioning. Patch releases are used for bug fixes, minor releases add new functionality and maintain backwards compatibility, and major versions contain breaking changes to the public API of the library. Links to the changes between individual versions can be found on the releases page.
"},{"location":"#get-involved","title":"Get Involved","text":"The iiif-prezi3
maintainers welcome contributions from the community - issues, pull requests, use cases, etc. We have a guideline document for contributions and a channel #iiif-prezi3
on the IIIF Slack workspace, which can be joined from the IIIF website's Get Involved page.
"},{"location":"code/","title":"Code reference","text":""},{"location":"code/#iiif_prezi3.AddImage","title":"AddImage
","text":"Source code in iiif_prezi3/helpers/add_image.py
class AddImage:\n\n def add_image(self, image_url, anno_id=None, anno_page_id=None, **kwargs):\n \"\"\"Adds an image to an existing canvas.\n\n Args:\n image_url (str): An HTTP URL which points to the image.\n anno_id (str): An HTTP URL for the annotation to which the image will be attached.\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n\n Returns:\n anno_page (AnnotationPage): the AnnotationPage with an Annotation and ResourceItem attached.\n \"\"\"\n body = ResourceItem(id=image_url, type='Image', **kwargs)\n annotation = Annotation(id=anno_id, body=body, target=self.id, motivation='painting', type='Annotation')\n anno_page = AnnotationPage(id=anno_page_id, type='AnnotationPage', items=[annotation])\n if not self.items:\n self.items = list()\n self.items.append(anno_page)\n return anno_page\n
"},{"location":"code/#iiif_prezi3.AddImage.add_image","title":"add_image(image_url, anno_id=None, anno_page_id=None, **kwargs)
","text":"Adds an image to an existing canvas.
Parameters:
Name Type Description Default image_url
str
An HTTP URL which points to the image.
required anno_id
str
An HTTP URL for the annotation to which the image will be attached.
None
anno_page_id
str
An HTTP URL for the annotation page to which the annotation will be attached.
None
Returns:
Name Type Description anno_page
AnnotationPage
the AnnotationPage with an Annotation and ResourceItem attached.
Source code in iiif_prezi3/helpers/add_image.py
def add_image(self, image_url, anno_id=None, anno_page_id=None, **kwargs):\n \"\"\"Adds an image to an existing canvas.\n\n Args:\n image_url (str): An HTTP URL which points to the image.\n anno_id (str): An HTTP URL for the annotation to which the image will be attached.\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n\n Returns:\n anno_page (AnnotationPage): the AnnotationPage with an Annotation and ResourceItem attached.\n \"\"\"\n body = ResourceItem(id=image_url, type='Image', **kwargs)\n annotation = Annotation(id=anno_id, body=body, target=self.id, motivation='painting', type='Annotation')\n anno_page = AnnotationPage(id=anno_page_id, type='AnnotationPage', items=[annotation])\n if not self.items:\n self.items = list()\n self.items.append(anno_page)\n return anno_page\n
"},{"location":"code/#iiif_prezi3.AddItem","title":"AddItem
","text":"Source code in iiif_prezi3/helpers/add_item.py
class AddItem:\n def add_item(self, item):\n \"\"\"Add a IIIF Prezi3 object to the items list, creating it if it doesn't exist.\n\n Args:\n item (Union[Collection, Manifest, Canvas, AnnotationPage, Annotation, Range, Reference, SpecificResource, Item])): The object to be added\n \"\"\"\n if not self.items:\n self.items = []\n\n # If the item is a Manifest, and the target is a Collection, convert it to a reference\n if isinstance(item, Manifest) and isinstance(self, Collection):\n item = item.to_reference()\n\n self.items.append(item)\n self.items = self.items # Force Pydantic to validate?\n
"},{"location":"code/#iiif_prezi3.AddItem.add_item","title":"add_item(item)
","text":"Add a IIIF Prezi3 object to the items list, creating it if it doesn't exist.
Parameters:
Name Type Description Default item
Union[Collection, Manifest, Canvas, AnnotationPage, Annotation, Range, Reference, SpecificResource, Item]
The object to be added
required Source code in iiif_prezi3/helpers/add_item.py
def add_item(self, item):\n \"\"\"Add a IIIF Prezi3 object to the items list, creating it if it doesn't exist.\n\n Args:\n item (Union[Collection, Manifest, Canvas, AnnotationPage, Annotation, Range, Reference, SpecificResource, Item])): The object to be added\n \"\"\"\n if not self.items:\n self.items = []\n\n # If the item is a Manifest, and the target is a Collection, convert it to a reference\n if isinstance(item, Manifest) and isinstance(self, Collection):\n item = item.to_reference()\n\n self.items.append(item)\n self.items = self.items # Force Pydantic to validate?\n
"},{"location":"code/#iiif_prezi3.AddItemByReference","title":"AddItemByReference
","text":"Source code in iiif_prezi3/helpers/add_item.py
class AddItemByReference:\n def add_item_by_reference(self, item):\n \"\"\"Add a IIIF Prezi3 object by reference to the items list, creating it if it doesn't exist.\n\n Args:\n item (Union[Manifest, AnnotationPage, Collection, AnnotationCollection, Canvas])): The object to be added\n \"\"\"\n if not self.items:\n self.items = []\n\n item = item.to_reference()\n\n self.items.append(item)\n self.items = self.items # Force Pydantic to validate?\n
"},{"location":"code/#iiif_prezi3.AddItemByReference.add_item_by_reference","title":"add_item_by_reference(item)
","text":"Add a IIIF Prezi3 object by reference to the items list, creating it if it doesn't exist.
Parameters:
Name Type Description Default item
Union[Manifest, AnnotationPage, Collection, AnnotationCollection, Canvas]
The object to be added
required Source code in iiif_prezi3/helpers/add_item.py
def add_item_by_reference(self, item):\n \"\"\"Add a IIIF Prezi3 object by reference to the items list, creating it if it doesn't exist.\n\n Args:\n item (Union[Manifest, AnnotationPage, Collection, AnnotationCollection, Canvas])): The object to be added\n \"\"\"\n if not self.items:\n self.items = []\n\n item = item.to_reference()\n\n self.items.append(item)\n self.items = self.items # Force Pydantic to validate?\n
"},{"location":"code/#iiif_prezi3.AddLabel","title":"AddLabel
","text":"Source code in iiif_prezi3/helpers/add_label.py
class AddLabel:\n\n def add_label(self, value, language=None):\n \"\"\"Adds a label to an existing resource.\n\n Args:\n value (Union[str, list]): The label or labels to be added\n language (str): An optional language for the labels. If not provided it will default using the AutoLang configuration.\n \"\"\"\n if not self.label:\n if not language:\n self.label = value\n else:\n if type(value) != list:\n value = [value]\n self.label = {language: value}\n else:\n # fetch as dict not LngString\n curr = self.label\n if not language:\n language = configs['helpers.auto_fields.AutoLang'].auto_lang\n if language in curr:\n curr[language].append(value)\n else:\n if type(value) != list:\n value = [value]\n curr[language] = value\n self.label = curr\n
"},{"location":"code/#iiif_prezi3.AddLabel.add_label","title":"add_label(value, language=None)
","text":"Adds a label to an existing resource.
Parameters:
Name Type Description Default value
Union[str, list]
The label or labels to be added
required language
str
An optional language for the labels. If not provided it will default using the AutoLang configuration.
None
Source code in iiif_prezi3/helpers/add_label.py
def add_label(self, value, language=None):\n \"\"\"Adds a label to an existing resource.\n\n Args:\n value (Union[str, list]): The label or labels to be added\n language (str): An optional language for the labels. If not provided it will default using the AutoLang configuration.\n \"\"\"\n if not self.label:\n if not language:\n self.label = value\n else:\n if type(value) != list:\n value = [value]\n self.label = {language: value}\n else:\n # fetch as dict not LngString\n curr = self.label\n if not language:\n language = configs['helpers.auto_fields.AutoLang'].auto_lang\n if language in curr:\n curr[language].append(value)\n else:\n if type(value) != list:\n value = [value]\n curr[language] = value\n self.label = curr\n
"},{"location":"code/#iiif_prezi3.AddService","title":"AddService
","text":"Source code in iiif_prezi3/helpers/add_service.py
class AddService:\n def add_service(self, service):\n \"\"\"Add a IIIF Prezi service to the service list.\n\n Args:\n service (ServiceItem,ServiceItem1,Service): A iiif-prezi ServiceItem.\n \"\"\"\n if isinstance(service, (ServiceItem, ServiceItem1)):\n if not self.service:\n self.service = []\n self.service.append(service)\n self.service = self.service\n else:\n raise TypeError(\"Not a valid IIIF service.\")\n
"},{"location":"code/#iiif_prezi3.AddService.add_service","title":"add_service(service)
","text":"Add a IIIF Prezi service to the service list.
Parameters:
Name Type Description Default service
(ServiceItem, ServiceItem1, Service)
A iiif-prezi ServiceItem.
required Source code in iiif_prezi3/helpers/add_service.py
def add_service(self, service):\n \"\"\"Add a IIIF Prezi service to the service list.\n\n Args:\n service (ServiceItem,ServiceItem1,Service): A iiif-prezi ServiceItem.\n \"\"\"\n if isinstance(service, (ServiceItem, ServiceItem1)):\n if not self.service:\n self.service = []\n self.service.append(service)\n self.service = self.service\n else:\n raise TypeError(\"Not a valid IIIF service.\")\n
"},{"location":"code/#iiif_prezi3.AddThumbnail","title":"AddThumbnail
","text":"Source code in iiif_prezi3/helpers/add_thumbnail.py
class AddThumbnail:\n def add_thumbnail(self, image_url, **kwargs):\n \"\"\"Adds a thumbnail to an existing canvas.\n\n Args:\n image_url (str): An HTTP URL which points to the thumbnail.\n **kwargs (): see ResourceItem.\n\n Returns:\n new_thumbnail (ResourceItem): the newly-created thumbnail.\n \"\"\"\n new_thumbnail = ResourceItem(id=image_url, type='Image', **kwargs)\n if not self.thumbnail:\n self.thumbnail = list()\n self.thumbnail.append(new_thumbnail)\n return new_thumbnail\n
"},{"location":"code/#iiif_prezi3.AddThumbnail.add_thumbnail","title":"add_thumbnail(image_url, **kwargs)
","text":"Adds a thumbnail to an existing canvas.
Parameters:
Name Type Description Default image_url
str
An HTTP URL which points to the thumbnail.
required **kwargs
see ResourceItem.
{}
Returns:
Name Type Description new_thumbnail
ResourceItem
the newly-created thumbnail.
Source code in iiif_prezi3/helpers/add_thumbnail.py
def add_thumbnail(self, image_url, **kwargs):\n \"\"\"Adds a thumbnail to an existing canvas.\n\n Args:\n image_url (str): An HTTP URL which points to the thumbnail.\n **kwargs (): see ResourceItem.\n\n Returns:\n new_thumbnail (ResourceItem): the newly-created thumbnail.\n \"\"\"\n new_thumbnail = ResourceItem(id=image_url, type='Image', **kwargs)\n if not self.thumbnail:\n self.thumbnail = list()\n self.thumbnail.append(new_thumbnail)\n return new_thumbnail\n
"},{"location":"code/#iiif_prezi3.AnnotationHelpers","title":"AnnotationHelpers
","text":"Source code in iiif_prezi3/helpers/annotation_helpers.py
class AnnotationHelpers:\n\n def add_annotation(self, annotation, anno_page_id=None):\n \"\"\"Adds the annotation object to the (AnnotationPage object in the) annotations property.\n\n Creates an AnnotationPage object if it doesn't exist.\n\n Args:\n annotation (Annotation): the Annotation to add\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n\n Returns:\n annotation (Annotation): the Annotation attached to the AnnotationPage.\n\n \"\"\"\n if not self.annotations:\n self.annotations = list()\n\n if len(self.annotations) == 0:\n # add empty AnnotationPage\n anno_page = AnnotationPage(id=anno_page_id, items=[])\n self.annotations.append(anno_page)\n else:\n anno_page = self.annotations[0]\n\n anno_page.items.append(annotation)\n\n return annotation\n\n def make_annotation(self, anno_page_id=None, **kwargs):\n \"\"\"Creates an annotation object and adds it to the annotations property using .add_annotation().\n\n Args:\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n **kwargs (): see Annotation.\n \"\"\"\n annotation = Annotation(**kwargs)\n self.add_annotation(annotation, anno_page_id=anno_page_id)\n return annotation\n
"},{"location":"code/#iiif_prezi3.AnnotationHelpers.add_annotation","title":"add_annotation(annotation, anno_page_id=None)
","text":"Adds the annotation object to the (AnnotationPage object in the) annotations property.
Creates an AnnotationPage object if it doesn't exist.
Parameters:
Name Type Description Default annotation
Annotation
the Annotation to add
required anno_page_id
str
An HTTP URL for the annotation page to which the annotation will be attached.
None
Returns:
Name Type Description annotation
Annotation
the Annotation attached to the AnnotationPage.
Source code in iiif_prezi3/helpers/annotation_helpers.py
def add_annotation(self, annotation, anno_page_id=None):\n \"\"\"Adds the annotation object to the (AnnotationPage object in the) annotations property.\n\n Creates an AnnotationPage object if it doesn't exist.\n\n Args:\n annotation (Annotation): the Annotation to add\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n\n Returns:\n annotation (Annotation): the Annotation attached to the AnnotationPage.\n\n \"\"\"\n if not self.annotations:\n self.annotations = list()\n\n if len(self.annotations) == 0:\n # add empty AnnotationPage\n anno_page = AnnotationPage(id=anno_page_id, items=[])\n self.annotations.append(anno_page)\n else:\n anno_page = self.annotations[0]\n\n anno_page.items.append(annotation)\n\n return annotation\n
"},{"location":"code/#iiif_prezi3.AnnotationHelpers.make_annotation","title":"make_annotation(anno_page_id=None, **kwargs)
","text":"Creates an annotation object and adds it to the annotations property using .add_annotation().
Parameters:
Name Type Description Default anno_page_id
str
An HTTP URL for the annotation page to which the annotation will be attached.
None
**kwargs
see Annotation.
{}
Source code in iiif_prezi3/helpers/annotation_helpers.py
def make_annotation(self, anno_page_id=None, **kwargs):\n \"\"\"Creates an annotation object and adds it to the annotations property using .add_annotation().\n\n Args:\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n **kwargs (): see Annotation.\n \"\"\"\n annotation = Annotation(**kwargs)\n self.add_annotation(annotation, anno_page_id=anno_page_id)\n return annotation\n
"},{"location":"code/#iiif_prezi3.CreateCanvasFromIIIF","title":"CreateCanvasFromIIIF
","text":"Source code in iiif_prezi3/helpers/create_canvas_from_iiif.py
class CreateCanvasFromIIIF:\n # should probably be added to canvas helpers\n\n def create_canvas_from_iiif(self, url, anno_id=None, anno_page_id=None, **kwargs):\n \"\"\"Create a canvas from a IIIF Image URL.\n\n Creates a canvas from a IIIF Image service passing any kwargs to the Canvas.\n\n Args:\n url (str): An HTTP URL at which at a IIIF Image is available.\n anno_id (str): An HTTP URL for the annotation to which the image will be attached.\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n **kwargs (): see Canvas\n\n Returns:\n canvas (Canvas): the Canvas created from the IIIF Image.\n\n \"\"\"\n canvas = Canvas(**kwargs)\n\n body = ResourceItem(id=\"http://example.com\", type=\"Image\")\n infoJson = body.set_hwd_from_iiif(url)\n\n # Will need to handle IIIF 2...\n if 'type' not in infoJson:\n # Assume v2\n\n # V2 profile contains profile URI plus extra features\n profile = ''\n for item in infoJson['profile']:\n if isinstance(item, str):\n profile = item\n break\n\n service = ServiceItem1(id=infoJson['@id'], profile=profile, type=\"ImageService2\")\n body.service = [service]\n body.id = f'{infoJson[\"@id\"]}/full/full/0/default.jpg'\n body.format = \"image/jpeg\"\n else:\n service = ServiceItem(id=infoJson['id'], profile=infoJson['profile'], type=infoJson['type'])\n body.service = [service]\n body.id = f'{infoJson[\"id\"]}/full/max/0/default.jpg'\n body.format = \"image/jpeg\"\n\n annotation = Annotation(id=anno_id, motivation='painting', body=body, target=canvas.id)\n\n annotationPage = AnnotationPage(id=anno_page_id)\n annotationPage.add_item(annotation)\n\n canvas.add_item(annotationPage)\n canvas.set_hwd(infoJson['height'], infoJson['width'])\n\n return canvas\n\n def make_canvas_from_iiif(self, url, **kwargs):\n canvas = self.create_canvas_from_iiif(url, **kwargs)\n\n self.add_item(canvas)\n return canvas\n
"},{"location":"code/#iiif_prezi3.CreateCanvasFromIIIF.create_canvas_from_iiif","title":"create_canvas_from_iiif(url, anno_id=None, anno_page_id=None, **kwargs)
","text":"Create a canvas from a IIIF Image URL.
Creates a canvas from a IIIF Image service passing any kwargs to the Canvas.
Parameters:
Name Type Description Default url
str
An HTTP URL at which at a IIIF Image is available.
required anno_id
str
An HTTP URL for the annotation to which the image will be attached.
None
anno_page_id
str
An HTTP URL for the annotation page to which the annotation will be attached.
None
**kwargs
see Canvas
{}
Returns:
Name Type Description canvas
Canvas
the Canvas created from the IIIF Image.
Source code in iiif_prezi3/helpers/create_canvas_from_iiif.py
def create_canvas_from_iiif(self, url, anno_id=None, anno_page_id=None, **kwargs):\n \"\"\"Create a canvas from a IIIF Image URL.\n\n Creates a canvas from a IIIF Image service passing any kwargs to the Canvas.\n\n Args:\n url (str): An HTTP URL at which at a IIIF Image is available.\n anno_id (str): An HTTP URL for the annotation to which the image will be attached.\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n **kwargs (): see Canvas\n\n Returns:\n canvas (Canvas): the Canvas created from the IIIF Image.\n\n \"\"\"\n canvas = Canvas(**kwargs)\n\n body = ResourceItem(id=\"http://example.com\", type=\"Image\")\n infoJson = body.set_hwd_from_iiif(url)\n\n # Will need to handle IIIF 2...\n if 'type' not in infoJson:\n # Assume v2\n\n # V2 profile contains profile URI plus extra features\n profile = ''\n for item in infoJson['profile']:\n if isinstance(item, str):\n profile = item\n break\n\n service = ServiceItem1(id=infoJson['@id'], profile=profile, type=\"ImageService2\")\n body.service = [service]\n body.id = f'{infoJson[\"@id\"]}/full/full/0/default.jpg'\n body.format = \"image/jpeg\"\n else:\n service = ServiceItem(id=infoJson['id'], profile=infoJson['profile'], type=infoJson['type'])\n body.service = [service]\n body.id = f'{infoJson[\"id\"]}/full/max/0/default.jpg'\n body.format = \"image/jpeg\"\n\n annotation = Annotation(id=anno_id, motivation='painting', body=body, target=canvas.id)\n\n annotationPage = AnnotationPage(id=anno_page_id)\n annotationPage.add_item(annotation)\n\n canvas.add_item(annotationPage)\n canvas.set_hwd(infoJson['height'], infoJson['width'])\n\n return canvas\n
"},{"location":"code/#iiif_prezi3.MakeCanvas","title":"MakeCanvas
","text":"Source code in iiif_prezi3/helpers/make_canvas.py
class MakeCanvas:\n\n def make_canvas(self, **kwargs):\n \"\"\"Add a Canvas to a Manifest.\n\n Creates a new Canvas, appends it to the\n calling Manifest items and returns the newly created Canvas.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n canvas = Canvas(**kwargs)\n self.add_item(canvas)\n return canvas\n
"},{"location":"code/#iiif_prezi3.MakeCanvas.make_canvas","title":"make_canvas(**kwargs)
","text":"Add a Canvas to a Manifest.
Creates a new Canvas, appends it to the calling Manifest items and returns the newly created Canvas. Accepts keyword arguments to customize the resulting instance.
Source code in iiif_prezi3/helpers/make_canvas.py
def make_canvas(self, **kwargs):\n \"\"\"Add a Canvas to a Manifest.\n\n Creates a new Canvas, appends it to the\n calling Manifest items and returns the newly created Canvas.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n canvas = Canvas(**kwargs)\n self.add_item(canvas)\n return canvas\n
"},{"location":"code/#iiif_prezi3.MakeCollection","title":"MakeCollection
","text":"Source code in iiif_prezi3/helpers/make_collection.py
class MakeCollection:\n\n def make_collection(self, **kwargs):\n \"\"\"Create a Collection.\n\n Creates a new collection, adds it to the calling Collection `items`\n and returns the newly created object. Accepts keyword arguments to\n customize the resulting instance.\n \"\"\"\n child_collection = Collection(**kwargs)\n self.add_item(child_collection)\n return child_collection\n
"},{"location":"code/#iiif_prezi3.MakeCollection.make_collection","title":"make_collection(**kwargs)
","text":"Create a Collection.
Creates a new collection, adds it to the calling Collection items
and returns the newly created object. Accepts keyword arguments to customize the resulting instance.
Source code in iiif_prezi3/helpers/make_collection.py
def make_collection(self, **kwargs):\n \"\"\"Create a Collection.\n\n Creates a new collection, adds it to the calling Collection `items`\n and returns the newly created object. Accepts keyword arguments to\n customize the resulting instance.\n \"\"\"\n child_collection = Collection(**kwargs)\n self.add_item(child_collection)\n return child_collection\n
"},{"location":"code/#iiif_prezi3.MakeManifest","title":"MakeManifest
","text":"Source code in iiif_prezi3/helpers/make_manifest.py
class MakeManifest:\n\n def make_manifest(self, **kwargs):\n \"\"\"Add a Manifest to a Collection.\n\n Creates a new Manifest, adds a Reference to it to the\n calling Collection items and returns the newly created Manifest.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n manifest = Manifest(**kwargs)\n self.add_item(manifest)\n return manifest\n
"},{"location":"code/#iiif_prezi3.MakeManifest.make_manifest","title":"make_manifest(**kwargs)
","text":"Add a Manifest to a Collection.
Creates a new Manifest, adds a Reference to it to the calling Collection items and returns the newly created Manifest. Accepts keyword arguments to customize the resulting instance.
Source code in iiif_prezi3/helpers/make_manifest.py
def make_manifest(self, **kwargs):\n \"\"\"Add a Manifest to a Collection.\n\n Creates a new Manifest, adds a Reference to it to the\n calling Collection items and returns the newly created Manifest.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n manifest = Manifest(**kwargs)\n self.add_item(manifest)\n return manifest\n
"},{"location":"code/#iiif_prezi3.MakeRange","title":"MakeRange
","text":"Source code in iiif_prezi3/helpers/make_range.py
class MakeRange:\n\n def make_range(self, **kwargs):\n \"\"\"Create a Range and add it to the calling Collection or Range.\n\n Creates a new Range, adds it to the calling object and returns the newly created Range.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n range = Range(**kwargs)\n if type(self) == Manifest:\n if self.structures:\n self.structures.append(range)\n else:\n self.structures = [range]\n elif type(self) == Range:\n self.add_item(range)\n return range\n
"},{"location":"code/#iiif_prezi3.MakeRange.make_range","title":"make_range(**kwargs)
","text":"Create a Range and add it to the calling Collection or Range.
Creates a new Range, adds it to the calling object and returns the newly created Range. Accepts keyword arguments to customize the resulting instance.
Source code in iiif_prezi3/helpers/make_range.py
def make_range(self, **kwargs):\n \"\"\"Create a Range and add it to the calling Collection or Range.\n\n Creates a new Range, adds it to the calling object and returns the newly created Range.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n range = Range(**kwargs)\n if type(self) == Manifest:\n if self.structures:\n self.structures.append(range)\n else:\n self.structures = [range]\n elif type(self) == Range:\n self.add_item(range)\n return range\n
"},{"location":"code/#iiif_prezi3.MakeService","title":"MakeService
","text":"Source code in iiif_prezi3/helpers/make_service.py
class MakeService:\n def make_service(self, id, type, version=3, **kwargs):\n \"\"\"Make a IIIF Prezi service of the desired IIIF API version and adds it to the service list.\n\n Args:\n id (AnyUrl): The id of the service.\n type (str): The type of the service.\n version (int): The API version of the service. Defaults to 3.\n **kwargs (): Arbitrary keyword arguments.\n\n Raises:\n ValueError: If an invalid IIIF API version is provided.\n\n Returns:\n service (Union[ServiceItem, ServiceItem1]): A service instance of the selected version.\n \"\"\"\n serviceversions = {\n 2: ServiceItem1,\n 3: ServiceItem\n }\n if version not in serviceversions:\n raise ValueError(f\"Version: {version} is not a valid IIIF API service version.\")\n service = serviceversions[version](id=id, type=type, **kwargs)\n self.add_service(service)\n return service\n
"},{"location":"code/#iiif_prezi3.MakeService.make_service","title":"make_service(id, type, version=3, **kwargs)
","text":"Make a IIIF Prezi service of the desired IIIF API version and adds it to the service list.
Parameters:
Name Type Description Default id
AnyUrl
The id of the service.
required type
str
The type of the service.
required version
int
The API version of the service. Defaults to 3.
3
**kwargs
Arbitrary keyword arguments.
{}
Raises:
Type Description ValueError
If an invalid IIIF API version is provided.
Returns:
Name Type Description service
Union[ServiceItem, ServiceItem1]
A service instance of the selected version.
Source code in iiif_prezi3/helpers/make_service.py
def make_service(self, id, type, version=3, **kwargs):\n \"\"\"Make a IIIF Prezi service of the desired IIIF API version and adds it to the service list.\n\n Args:\n id (AnyUrl): The id of the service.\n type (str): The type of the service.\n version (int): The API version of the service. Defaults to 3.\n **kwargs (): Arbitrary keyword arguments.\n\n Raises:\n ValueError: If an invalid IIIF API version is provided.\n\n Returns:\n service (Union[ServiceItem, ServiceItem1]): A service instance of the selected version.\n \"\"\"\n serviceversions = {\n 2: ServiceItem1,\n 3: ServiceItem\n }\n if version not in serviceversions:\n raise ValueError(f\"Version: {version} is not a valid IIIF API service version.\")\n service = serviceversions[version](id=id, type=type, **kwargs)\n self.add_service(service)\n return service\n
"},{"location":"code/#iiif_prezi3.SetHeightWidthDurationFileHelper","title":"SetHeightWidthDurationFileHelper
","text":"Source code in iiif_prezi3/helpers/set_hwd_from_file.py
class SetHeightWidthDurationFileHelper:\n def set_hwd_from_file(self, file_path_or_object):\n \"\"\"Introspect a file and set the height, width, and duration properties.\n\n Args:\n file_path_or_object (Union[str, fp]): the file path or file object to introspect\n \"\"\"\n if isinstance(file_path_or_object, str) or isinstance(file_path_or_object, os.PathLike):\n filetype, _ = mimetypes.guess_type(file_path_or_object)\n if not filetype.startswith(\"image/\"):\n raise NotImplementedError\n\n tmp_image = Image.open(file_path_or_object)\n w, h = tmp_image.size\n self.set_hwd(h, w, None)\n tmp_image.close()\n
"},{"location":"code/#iiif_prezi3.SetHeightWidthDurationFileHelper.set_hwd_from_file","title":"set_hwd_from_file(file_path_or_object)
","text":"Introspect a file and set the height, width, and duration properties.
Parameters:
Name Type Description Default file_path_or_object
Union[str, fp]
the file path or file object to introspect
required Source code in iiif_prezi3/helpers/set_hwd_from_file.py
def set_hwd_from_file(self, file_path_or_object):\n \"\"\"Introspect a file and set the height, width, and duration properties.\n\n Args:\n file_path_or_object (Union[str, fp]): the file path or file object to introspect\n \"\"\"\n if isinstance(file_path_or_object, str) or isinstance(file_path_or_object, os.PathLike):\n filetype, _ = mimetypes.guess_type(file_path_or_object)\n if not filetype.startswith(\"image/\"):\n raise NotImplementedError\n\n tmp_image = Image.open(file_path_or_object)\n w, h = tmp_image.size\n self.set_hwd(h, w, None)\n tmp_image.close()\n
"},{"location":"code/#iiif_prezi3.SetHwd","title":"SetHwd
","text":"Source code in iiif_prezi3/helpers/set_hwd.py
class SetHwd:\n def set_hwd(self, height=None, width=None, duration=None):\n \"\"\"Set the height, width, and duration properties allowing nulls.\n\n Args:\n height (int): The height of the resource or the canvas\n width (int): The width of the resource or the canvas\n duration (float): The duration of the resource\n \"\"\"\n if not (duration or height or width):\n raise TypeError(\"At least one of height, width, or duration must be set\")\n if height and not width:\n raise TypeError(\"width must be set if height is set\")\n if width and not height:\n raise TypeError(\"height must be set if width is set\")\n self.height = height\n self.width = width\n self.duration = duration\n
"},{"location":"code/#iiif_prezi3.SetHwd.set_hwd","title":"set_hwd(height=None, width=None, duration=None)
","text":"Set the height, width, and duration properties allowing nulls.
Parameters:
Name Type Description Default height
int
The height of the resource or the canvas
None
width
int
The width of the resource or the canvas
None
duration
float
The duration of the resource
None
Source code in iiif_prezi3/helpers/set_hwd.py
def set_hwd(self, height=None, width=None, duration=None):\n \"\"\"Set the height, width, and duration properties allowing nulls.\n\n Args:\n height (int): The height of the resource or the canvas\n width (int): The width of the resource or the canvas\n duration (float): The duration of the resource\n \"\"\"\n if not (duration or height or width):\n raise TypeError(\"At least one of height, width, or duration must be set\")\n if height and not width:\n raise TypeError(\"width must be set if height is set\")\n if width and not height:\n raise TypeError(\"height must be set if width is set\")\n self.height = height\n self.width = width\n self.duration = duration\n
"},{"location":"code/#iiif_prezi3.SetHwdFromIIIF","title":"SetHwdFromIIIF
","text":"Source code in iiif_prezi3/helpers/set_hwd_from_iiif.py
class SetHwdFromIIIF:\n # should probably be added to canvas helpers\n\n def set_hwd_from_iiif(self, url):\n \"\"\"Set height and width on a Canvas object.\n\n Requests IIIF Image information remotely for an\n image resource and sets resulting height and width.\n This method will return the info.json\n\n Args:\n url (str): An HTTP URL for the IIIF image endpoint.\n \"\"\"\n # resource url may or may not end with info.json;\n # add if not present\n if not url.endswith(\"info.json\"):\n url = f\"{ url.rstrip('/') }/info.json\"\n\n response = requests.get(url)\n # if response is not 200, raise exception\n if response.status_code != requests.codes.ok:\n response.raise_for_status()\n # if response is not valid json, request will raise\n # requests.exceptions.JSONDecodeError\n # \u2014\u00a0handle or document and let calling code handle?\n resource_info = response.json()\n self.set_hwd(resource_info.get(\"height\"), resource_info.get(\"width\"))\n\n return resource_info\n
"},{"location":"code/#iiif_prezi3.SetHwdFromIIIF.set_hwd_from_iiif","title":"set_hwd_from_iiif(url)
","text":"Set height and width on a Canvas object.
Requests IIIF Image information remotely for an image resource and sets resulting height and width. This method will return the info.json
Parameters:
Name Type Description Default url
str
An HTTP URL for the IIIF image endpoint.
required Source code in iiif_prezi3/helpers/set_hwd_from_iiif.py
def set_hwd_from_iiif(self, url):\n \"\"\"Set height and width on a Canvas object.\n\n Requests IIIF Image information remotely for an\n image resource and sets resulting height and width.\n This method will return the info.json\n\n Args:\n url (str): An HTTP URL for the IIIF image endpoint.\n \"\"\"\n # resource url may or may not end with info.json;\n # add if not present\n if not url.endswith(\"info.json\"):\n url = f\"{ url.rstrip('/') }/info.json\"\n\n response = requests.get(url)\n # if response is not 200, raise exception\n if response.status_code != requests.codes.ok:\n response.raise_for_status()\n # if response is not valid json, request will raise\n # requests.exceptions.JSONDecodeError\n # \u2014\u00a0handle or document and let calling code handle?\n resource_info = response.json()\n self.set_hwd(resource_info.get(\"height\"), resource_info.get(\"width\"))\n\n return resource_info\n
"},{"location":"code/#iiif_prezi3.ToReference","title":"ToReference
","text":"Source code in iiif_prezi3/helpers/to_reference.py
class ToReference:\n\n def to_reference(self):\n \"\"\"Returns a Reference object that points to the calling object.\"\"\"\n # Only try to set thumbnail if it's a Class that can have one\n if isinstance(self, (Collection, Manifest, Canvas, AnnotationPage, Annotation, AnnotationCollection, Range)):\n thumbnail = self.thumbnail\n else:\n thumbnail = None\n\n # Currently the skeleton Reference requires a label, but some Referenceable objects may not have one (e.g AnnotationPage)\n # TODO: Remove this when the Schema is updated to have different reference types\n if not self.label:\n self.label = \"\"\n\n # Ensure that we use a specific Reference type if it exists\n if isinstance(self, Manifest):\n target_type = ManifestRef\n elif isinstance(self, Collection):\n target_type = CollectionRef\n elif isinstance(self, Canvas):\n target_type = CanvasRef\n elif isinstance(self, Range):\n target_type = RangeRef\n else:\n target_type = Reference\n\n return target_type(id=self.id, label=self.label, type=self.type, thumbnail=thumbnail)\n
"},{"location":"code/#iiif_prezi3.ToReference.to_reference","title":"to_reference()
","text":"Returns a Reference object that points to the calling object.
Source code in iiif_prezi3/helpers/to_reference.py
def to_reference(self):\n \"\"\"Returns a Reference object that points to the calling object.\"\"\"\n # Only try to set thumbnail if it's a Class that can have one\n if isinstance(self, (Collection, Manifest, Canvas, AnnotationPage, Annotation, AnnotationCollection, Range)):\n thumbnail = self.thumbnail\n else:\n thumbnail = None\n\n # Currently the skeleton Reference requires a label, but some Referenceable objects may not have one (e.g AnnotationPage)\n # TODO: Remove this when the Schema is updated to have different reference types\n if not self.label:\n self.label = \"\"\n\n # Ensure that we use a specific Reference type if it exists\n if isinstance(self, Manifest):\n target_type = ManifestRef\n elif isinstance(self, Collection):\n target_type = CollectionRef\n elif isinstance(self, Canvas):\n target_type = CanvasRef\n elif isinstance(self, Range):\n target_type = RangeRef\n else:\n target_type = Reference\n\n return target_type(id=self.id, label=self.label, type=self.type, thumbnail=thumbnail)\n
"},{"location":"code/#iiif_prezi3.helpers","title":"helpers
","text":""},{"location":"code/#iiif_prezi3.helpers.add_image","title":"add_image
","text":""},{"location":"code/#iiif_prezi3.helpers.add_image.AddImage","title":"AddImage
","text":"Source code in iiif_prezi3/helpers/add_image.py
class AddImage:\n\n def add_image(self, image_url, anno_id=None, anno_page_id=None, **kwargs):\n \"\"\"Adds an image to an existing canvas.\n\n Args:\n image_url (str): An HTTP URL which points to the image.\n anno_id (str): An HTTP URL for the annotation to which the image will be attached.\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n\n Returns:\n anno_page (AnnotationPage): the AnnotationPage with an Annotation and ResourceItem attached.\n \"\"\"\n body = ResourceItem(id=image_url, type='Image', **kwargs)\n annotation = Annotation(id=anno_id, body=body, target=self.id, motivation='painting', type='Annotation')\n anno_page = AnnotationPage(id=anno_page_id, type='AnnotationPage', items=[annotation])\n if not self.items:\n self.items = list()\n self.items.append(anno_page)\n return anno_page\n
"},{"location":"code/#iiif_prezi3.helpers.add_image.AddImage.add_image","title":"add_image(image_url, anno_id=None, anno_page_id=None, **kwargs)
","text":"Adds an image to an existing canvas.
Parameters:
Name Type Description Default image_url
str
An HTTP URL which points to the image.
required anno_id
str
An HTTP URL for the annotation to which the image will be attached.
None
anno_page_id
str
An HTTP URL for the annotation page to which the annotation will be attached.
None
Returns:
Name Type Description anno_page
AnnotationPage
the AnnotationPage with an Annotation and ResourceItem attached.
Source code in iiif_prezi3/helpers/add_image.py
def add_image(self, image_url, anno_id=None, anno_page_id=None, **kwargs):\n \"\"\"Adds an image to an existing canvas.\n\n Args:\n image_url (str): An HTTP URL which points to the image.\n anno_id (str): An HTTP URL for the annotation to which the image will be attached.\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n\n Returns:\n anno_page (AnnotationPage): the AnnotationPage with an Annotation and ResourceItem attached.\n \"\"\"\n body = ResourceItem(id=image_url, type='Image', **kwargs)\n annotation = Annotation(id=anno_id, body=body, target=self.id, motivation='painting', type='Annotation')\n anno_page = AnnotationPage(id=anno_page_id, type='AnnotationPage', items=[annotation])\n if not self.items:\n self.items = list()\n self.items.append(anno_page)\n return anno_page\n
"},{"location":"code/#iiif_prezi3.helpers.add_item","title":"add_item
","text":""},{"location":"code/#iiif_prezi3.helpers.add_item.AddItem","title":"AddItem
","text":"Source code in iiif_prezi3/helpers/add_item.py
class AddItem:\n def add_item(self, item):\n \"\"\"Add a IIIF Prezi3 object to the items list, creating it if it doesn't exist.\n\n Args:\n item (Union[Collection, Manifest, Canvas, AnnotationPage, Annotation, Range, Reference, SpecificResource, Item])): The object to be added\n \"\"\"\n if not self.items:\n self.items = []\n\n # If the item is a Manifest, and the target is a Collection, convert it to a reference\n if isinstance(item, Manifest) and isinstance(self, Collection):\n item = item.to_reference()\n\n self.items.append(item)\n self.items = self.items # Force Pydantic to validate?\n
"},{"location":"code/#iiif_prezi3.helpers.add_item.AddItem.add_item","title":"add_item(item)
","text":"Add a IIIF Prezi3 object to the items list, creating it if it doesn't exist.
Parameters:
Name Type Description Default item
Union[Collection, Manifest, Canvas, AnnotationPage, Annotation, Range, Reference, SpecificResource, Item]
The object to be added
required Source code in iiif_prezi3/helpers/add_item.py
def add_item(self, item):\n \"\"\"Add a IIIF Prezi3 object to the items list, creating it if it doesn't exist.\n\n Args:\n item (Union[Collection, Manifest, Canvas, AnnotationPage, Annotation, Range, Reference, SpecificResource, Item])): The object to be added\n \"\"\"\n if not self.items:\n self.items = []\n\n # If the item is a Manifest, and the target is a Collection, convert it to a reference\n if isinstance(item, Manifest) and isinstance(self, Collection):\n item = item.to_reference()\n\n self.items.append(item)\n self.items = self.items # Force Pydantic to validate?\n
"},{"location":"code/#iiif_prezi3.helpers.add_item.AddItemByReference","title":"AddItemByReference
","text":"Source code in iiif_prezi3/helpers/add_item.py
class AddItemByReference:\n def add_item_by_reference(self, item):\n \"\"\"Add a IIIF Prezi3 object by reference to the items list, creating it if it doesn't exist.\n\n Args:\n item (Union[Manifest, AnnotationPage, Collection, AnnotationCollection, Canvas])): The object to be added\n \"\"\"\n if not self.items:\n self.items = []\n\n item = item.to_reference()\n\n self.items.append(item)\n self.items = self.items # Force Pydantic to validate?\n
"},{"location":"code/#iiif_prezi3.helpers.add_item.AddItemByReference.add_item_by_reference","title":"add_item_by_reference(item)
","text":"Add a IIIF Prezi3 object by reference to the items list, creating it if it doesn't exist.
Parameters:
Name Type Description Default item
Union[Manifest, AnnotationPage, Collection, AnnotationCollection, Canvas]
The object to be added
required Source code in iiif_prezi3/helpers/add_item.py
def add_item_by_reference(self, item):\n \"\"\"Add a IIIF Prezi3 object by reference to the items list, creating it if it doesn't exist.\n\n Args:\n item (Union[Manifest, AnnotationPage, Collection, AnnotationCollection, Canvas])): The object to be added\n \"\"\"\n if not self.items:\n self.items = []\n\n item = item.to_reference()\n\n self.items.append(item)\n self.items = self.items # Force Pydantic to validate?\n
"},{"location":"code/#iiif_prezi3.helpers.add_label","title":"add_label
","text":""},{"location":"code/#iiif_prezi3.helpers.add_label.AddLabel","title":"AddLabel
","text":"Source code in iiif_prezi3/helpers/add_label.py
class AddLabel:\n\n def add_label(self, value, language=None):\n \"\"\"Adds a label to an existing resource.\n\n Args:\n value (Union[str, list]): The label or labels to be added\n language (str): An optional language for the labels. If not provided it will default using the AutoLang configuration.\n \"\"\"\n if not self.label:\n if not language:\n self.label = value\n else:\n if type(value) != list:\n value = [value]\n self.label = {language: value}\n else:\n # fetch as dict not LngString\n curr = self.label\n if not language:\n language = configs['helpers.auto_fields.AutoLang'].auto_lang\n if language in curr:\n curr[language].append(value)\n else:\n if type(value) != list:\n value = [value]\n curr[language] = value\n self.label = curr\n
"},{"location":"code/#iiif_prezi3.helpers.add_label.AddLabel.add_label","title":"add_label(value, language=None)
","text":"Adds a label to an existing resource.
Parameters:
Name Type Description Default value
Union[str, list]
The label or labels to be added
required language
str
An optional language for the labels. If not provided it will default using the AutoLang configuration.
None
Source code in iiif_prezi3/helpers/add_label.py
def add_label(self, value, language=None):\n \"\"\"Adds a label to an existing resource.\n\n Args:\n value (Union[str, list]): The label or labels to be added\n language (str): An optional language for the labels. If not provided it will default using the AutoLang configuration.\n \"\"\"\n if not self.label:\n if not language:\n self.label = value\n else:\n if type(value) != list:\n value = [value]\n self.label = {language: value}\n else:\n # fetch as dict not LngString\n curr = self.label\n if not language:\n language = configs['helpers.auto_fields.AutoLang'].auto_lang\n if language in curr:\n curr[language].append(value)\n else:\n if type(value) != list:\n value = [value]\n curr[language] = value\n self.label = curr\n
"},{"location":"code/#iiif_prezi3.helpers.add_service","title":"add_service
","text":""},{"location":"code/#iiif_prezi3.helpers.add_service.AddService","title":"AddService
","text":"Source code in iiif_prezi3/helpers/add_service.py
class AddService:\n def add_service(self, service):\n \"\"\"Add a IIIF Prezi service to the service list.\n\n Args:\n service (ServiceItem,ServiceItem1,Service): A iiif-prezi ServiceItem.\n \"\"\"\n if isinstance(service, (ServiceItem, ServiceItem1)):\n if not self.service:\n self.service = []\n self.service.append(service)\n self.service = self.service\n else:\n raise TypeError(\"Not a valid IIIF service.\")\n
"},{"location":"code/#iiif_prezi3.helpers.add_service.AddService.add_service","title":"add_service(service)
","text":"Add a IIIF Prezi service to the service list.
Parameters:
Name Type Description Default service
(ServiceItem, ServiceItem1, Service)
A iiif-prezi ServiceItem.
required Source code in iiif_prezi3/helpers/add_service.py
def add_service(self, service):\n \"\"\"Add a IIIF Prezi service to the service list.\n\n Args:\n service (ServiceItem,ServiceItem1,Service): A iiif-prezi ServiceItem.\n \"\"\"\n if isinstance(service, (ServiceItem, ServiceItem1)):\n if not self.service:\n self.service = []\n self.service.append(service)\n self.service = self.service\n else:\n raise TypeError(\"Not a valid IIIF service.\")\n
"},{"location":"code/#iiif_prezi3.helpers.add_thumbnail","title":"add_thumbnail
","text":""},{"location":"code/#iiif_prezi3.helpers.add_thumbnail.AddThumbnail","title":"AddThumbnail
","text":"Source code in iiif_prezi3/helpers/add_thumbnail.py
class AddThumbnail:\n def add_thumbnail(self, image_url, **kwargs):\n \"\"\"Adds a thumbnail to an existing canvas.\n\n Args:\n image_url (str): An HTTP URL which points to the thumbnail.\n **kwargs (): see ResourceItem.\n\n Returns:\n new_thumbnail (ResourceItem): the newly-created thumbnail.\n \"\"\"\n new_thumbnail = ResourceItem(id=image_url, type='Image', **kwargs)\n if not self.thumbnail:\n self.thumbnail = list()\n self.thumbnail.append(new_thumbnail)\n return new_thumbnail\n
"},{"location":"code/#iiif_prezi3.helpers.add_thumbnail.AddThumbnail.add_thumbnail","title":"add_thumbnail(image_url, **kwargs)
","text":"Adds a thumbnail to an existing canvas.
Parameters:
Name Type Description Default image_url
str
An HTTP URL which points to the thumbnail.
required **kwargs
see ResourceItem.
{}
Returns:
Name Type Description new_thumbnail
ResourceItem
the newly-created thumbnail.
Source code in iiif_prezi3/helpers/add_thumbnail.py
def add_thumbnail(self, image_url, **kwargs):\n \"\"\"Adds a thumbnail to an existing canvas.\n\n Args:\n image_url (str): An HTTP URL which points to the thumbnail.\n **kwargs (): see ResourceItem.\n\n Returns:\n new_thumbnail (ResourceItem): the newly-created thumbnail.\n \"\"\"\n new_thumbnail = ResourceItem(id=image_url, type='Image', **kwargs)\n if not self.thumbnail:\n self.thumbnail = list()\n self.thumbnail.append(new_thumbnail)\n return new_thumbnail\n
"},{"location":"code/#iiif_prezi3.helpers.annotation_helpers","title":"annotation_helpers
","text":""},{"location":"code/#iiif_prezi3.helpers.annotation_helpers.AnnotationHelpers","title":"AnnotationHelpers
","text":"Source code in iiif_prezi3/helpers/annotation_helpers.py
class AnnotationHelpers:\n\n def add_annotation(self, annotation, anno_page_id=None):\n \"\"\"Adds the annotation object to the (AnnotationPage object in the) annotations property.\n\n Creates an AnnotationPage object if it doesn't exist.\n\n Args:\n annotation (Annotation): the Annotation to add\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n\n Returns:\n annotation (Annotation): the Annotation attached to the AnnotationPage.\n\n \"\"\"\n if not self.annotations:\n self.annotations = list()\n\n if len(self.annotations) == 0:\n # add empty AnnotationPage\n anno_page = AnnotationPage(id=anno_page_id, items=[])\n self.annotations.append(anno_page)\n else:\n anno_page = self.annotations[0]\n\n anno_page.items.append(annotation)\n\n return annotation\n\n def make_annotation(self, anno_page_id=None, **kwargs):\n \"\"\"Creates an annotation object and adds it to the annotations property using .add_annotation().\n\n Args:\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n **kwargs (): see Annotation.\n \"\"\"\n annotation = Annotation(**kwargs)\n self.add_annotation(annotation, anno_page_id=anno_page_id)\n return annotation\n
"},{"location":"code/#iiif_prezi3.helpers.annotation_helpers.AnnotationHelpers.add_annotation","title":"add_annotation(annotation, anno_page_id=None)
","text":"Adds the annotation object to the (AnnotationPage object in the) annotations property.
Creates an AnnotationPage object if it doesn't exist.
Parameters:
Name Type Description Default annotation
Annotation
the Annotation to add
required anno_page_id
str
An HTTP URL for the annotation page to which the annotation will be attached.
None
Returns:
Name Type Description annotation
Annotation
the Annotation attached to the AnnotationPage.
Source code in iiif_prezi3/helpers/annotation_helpers.py
def add_annotation(self, annotation, anno_page_id=None):\n \"\"\"Adds the annotation object to the (AnnotationPage object in the) annotations property.\n\n Creates an AnnotationPage object if it doesn't exist.\n\n Args:\n annotation (Annotation): the Annotation to add\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n\n Returns:\n annotation (Annotation): the Annotation attached to the AnnotationPage.\n\n \"\"\"\n if not self.annotations:\n self.annotations = list()\n\n if len(self.annotations) == 0:\n # add empty AnnotationPage\n anno_page = AnnotationPage(id=anno_page_id, items=[])\n self.annotations.append(anno_page)\n else:\n anno_page = self.annotations[0]\n\n anno_page.items.append(annotation)\n\n return annotation\n
"},{"location":"code/#iiif_prezi3.helpers.annotation_helpers.AnnotationHelpers.make_annotation","title":"make_annotation(anno_page_id=None, **kwargs)
","text":"Creates an annotation object and adds it to the annotations property using .add_annotation().
Parameters:
Name Type Description Default anno_page_id
str
An HTTP URL for the annotation page to which the annotation will be attached.
None
**kwargs
see Annotation.
{}
Source code in iiif_prezi3/helpers/annotation_helpers.py
def make_annotation(self, anno_page_id=None, **kwargs):\n \"\"\"Creates an annotation object and adds it to the annotations property using .add_annotation().\n\n Args:\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n **kwargs (): see Annotation.\n \"\"\"\n annotation = Annotation(**kwargs)\n self.add_annotation(annotation, anno_page_id=anno_page_id)\n return annotation\n
"},{"location":"code/#iiif_prezi3.helpers.create_canvas_from_iiif","title":"create_canvas_from_iiif
","text":""},{"location":"code/#iiif_prezi3.helpers.create_canvas_from_iiif.CreateCanvasFromIIIF","title":"CreateCanvasFromIIIF
","text":"Source code in iiif_prezi3/helpers/create_canvas_from_iiif.py
class CreateCanvasFromIIIF:\n # should probably be added to canvas helpers\n\n def create_canvas_from_iiif(self, url, anno_id=None, anno_page_id=None, **kwargs):\n \"\"\"Create a canvas from a IIIF Image URL.\n\n Creates a canvas from a IIIF Image service passing any kwargs to the Canvas.\n\n Args:\n url (str): An HTTP URL at which at a IIIF Image is available.\n anno_id (str): An HTTP URL for the annotation to which the image will be attached.\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n **kwargs (): see Canvas\n\n Returns:\n canvas (Canvas): the Canvas created from the IIIF Image.\n\n \"\"\"\n canvas = Canvas(**kwargs)\n\n body = ResourceItem(id=\"http://example.com\", type=\"Image\")\n infoJson = body.set_hwd_from_iiif(url)\n\n # Will need to handle IIIF 2...\n if 'type' not in infoJson:\n # Assume v2\n\n # V2 profile contains profile URI plus extra features\n profile = ''\n for item in infoJson['profile']:\n if isinstance(item, str):\n profile = item\n break\n\n service = ServiceItem1(id=infoJson['@id'], profile=profile, type=\"ImageService2\")\n body.service = [service]\n body.id = f'{infoJson[\"@id\"]}/full/full/0/default.jpg'\n body.format = \"image/jpeg\"\n else:\n service = ServiceItem(id=infoJson['id'], profile=infoJson['profile'], type=infoJson['type'])\n body.service = [service]\n body.id = f'{infoJson[\"id\"]}/full/max/0/default.jpg'\n body.format = \"image/jpeg\"\n\n annotation = Annotation(id=anno_id, motivation='painting', body=body, target=canvas.id)\n\n annotationPage = AnnotationPage(id=anno_page_id)\n annotationPage.add_item(annotation)\n\n canvas.add_item(annotationPage)\n canvas.set_hwd(infoJson['height'], infoJson['width'])\n\n return canvas\n\n def make_canvas_from_iiif(self, url, **kwargs):\n canvas = self.create_canvas_from_iiif(url, **kwargs)\n\n self.add_item(canvas)\n return canvas\n
"},{"location":"code/#iiif_prezi3.helpers.create_canvas_from_iiif.CreateCanvasFromIIIF.create_canvas_from_iiif","title":"create_canvas_from_iiif(url, anno_id=None, anno_page_id=None, **kwargs)
","text":"Create a canvas from a IIIF Image URL.
Creates a canvas from a IIIF Image service passing any kwargs to the Canvas.
Parameters:
Name Type Description Default url
str
An HTTP URL at which at a IIIF Image is available.
required anno_id
str
An HTTP URL for the annotation to which the image will be attached.
None
anno_page_id
str
An HTTP URL for the annotation page to which the annotation will be attached.
None
**kwargs
see Canvas
{}
Returns:
Name Type Description canvas
Canvas
the Canvas created from the IIIF Image.
Source code in iiif_prezi3/helpers/create_canvas_from_iiif.py
def create_canvas_from_iiif(self, url, anno_id=None, anno_page_id=None, **kwargs):\n \"\"\"Create a canvas from a IIIF Image URL.\n\n Creates a canvas from a IIIF Image service passing any kwargs to the Canvas.\n\n Args:\n url (str): An HTTP URL at which at a IIIF Image is available.\n anno_id (str): An HTTP URL for the annotation to which the image will be attached.\n anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.\n **kwargs (): see Canvas\n\n Returns:\n canvas (Canvas): the Canvas created from the IIIF Image.\n\n \"\"\"\n canvas = Canvas(**kwargs)\n\n body = ResourceItem(id=\"http://example.com\", type=\"Image\")\n infoJson = body.set_hwd_from_iiif(url)\n\n # Will need to handle IIIF 2...\n if 'type' not in infoJson:\n # Assume v2\n\n # V2 profile contains profile URI plus extra features\n profile = ''\n for item in infoJson['profile']:\n if isinstance(item, str):\n profile = item\n break\n\n service = ServiceItem1(id=infoJson['@id'], profile=profile, type=\"ImageService2\")\n body.service = [service]\n body.id = f'{infoJson[\"@id\"]}/full/full/0/default.jpg'\n body.format = \"image/jpeg\"\n else:\n service = ServiceItem(id=infoJson['id'], profile=infoJson['profile'], type=infoJson['type'])\n body.service = [service]\n body.id = f'{infoJson[\"id\"]}/full/max/0/default.jpg'\n body.format = \"image/jpeg\"\n\n annotation = Annotation(id=anno_id, motivation='painting', body=body, target=canvas.id)\n\n annotationPage = AnnotationPage(id=anno_page_id)\n annotationPage.add_item(annotation)\n\n canvas.add_item(annotationPage)\n canvas.set_hwd(infoJson['height'], infoJson['width'])\n\n return canvas\n
"},{"location":"code/#iiif_prezi3.helpers.make_canvas","title":"make_canvas
","text":""},{"location":"code/#iiif_prezi3.helpers.make_canvas.MakeCanvas","title":"MakeCanvas
","text":"Source code in iiif_prezi3/helpers/make_canvas.py
class MakeCanvas:\n\n def make_canvas(self, **kwargs):\n \"\"\"Add a Canvas to a Manifest.\n\n Creates a new Canvas, appends it to the\n calling Manifest items and returns the newly created Canvas.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n canvas = Canvas(**kwargs)\n self.add_item(canvas)\n return canvas\n
"},{"location":"code/#iiif_prezi3.helpers.make_canvas.MakeCanvas.make_canvas","title":"make_canvas(**kwargs)
","text":"Add a Canvas to a Manifest.
Creates a new Canvas, appends it to the calling Manifest items and returns the newly created Canvas. Accepts keyword arguments to customize the resulting instance.
Source code in iiif_prezi3/helpers/make_canvas.py
def make_canvas(self, **kwargs):\n \"\"\"Add a Canvas to a Manifest.\n\n Creates a new Canvas, appends it to the\n calling Manifest items and returns the newly created Canvas.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n canvas = Canvas(**kwargs)\n self.add_item(canvas)\n return canvas\n
"},{"location":"code/#iiif_prezi3.helpers.make_collection","title":"make_collection
","text":""},{"location":"code/#iiif_prezi3.helpers.make_collection.MakeCollection","title":"MakeCollection
","text":"Source code in iiif_prezi3/helpers/make_collection.py
class MakeCollection:\n\n def make_collection(self, **kwargs):\n \"\"\"Create a Collection.\n\n Creates a new collection, adds it to the calling Collection `items`\n and returns the newly created object. Accepts keyword arguments to\n customize the resulting instance.\n \"\"\"\n child_collection = Collection(**kwargs)\n self.add_item(child_collection)\n return child_collection\n
"},{"location":"code/#iiif_prezi3.helpers.make_collection.MakeCollection.make_collection","title":"make_collection(**kwargs)
","text":"Create a Collection.
Creates a new collection, adds it to the calling Collection items
and returns the newly created object. Accepts keyword arguments to customize the resulting instance.
Source code in iiif_prezi3/helpers/make_collection.py
def make_collection(self, **kwargs):\n \"\"\"Create a Collection.\n\n Creates a new collection, adds it to the calling Collection `items`\n and returns the newly created object. Accepts keyword arguments to\n customize the resulting instance.\n \"\"\"\n child_collection = Collection(**kwargs)\n self.add_item(child_collection)\n return child_collection\n
"},{"location":"code/#iiif_prezi3.helpers.make_manifest","title":"make_manifest
","text":""},{"location":"code/#iiif_prezi3.helpers.make_manifest.MakeManifest","title":"MakeManifest
","text":"Source code in iiif_prezi3/helpers/make_manifest.py
class MakeManifest:\n\n def make_manifest(self, **kwargs):\n \"\"\"Add a Manifest to a Collection.\n\n Creates a new Manifest, adds a Reference to it to the\n calling Collection items and returns the newly created Manifest.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n manifest = Manifest(**kwargs)\n self.add_item(manifest)\n return manifest\n
"},{"location":"code/#iiif_prezi3.helpers.make_manifest.MakeManifest.make_manifest","title":"make_manifest(**kwargs)
","text":"Add a Manifest to a Collection.
Creates a new Manifest, adds a Reference to it to the calling Collection items and returns the newly created Manifest. Accepts keyword arguments to customize the resulting instance.
Source code in iiif_prezi3/helpers/make_manifest.py
def make_manifest(self, **kwargs):\n \"\"\"Add a Manifest to a Collection.\n\n Creates a new Manifest, adds a Reference to it to the\n calling Collection items and returns the newly created Manifest.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n manifest = Manifest(**kwargs)\n self.add_item(manifest)\n return manifest\n
"},{"location":"code/#iiif_prezi3.helpers.make_range","title":"make_range
","text":""},{"location":"code/#iiif_prezi3.helpers.make_range.MakeRange","title":"MakeRange
","text":"Source code in iiif_prezi3/helpers/make_range.py
class MakeRange:\n\n def make_range(self, **kwargs):\n \"\"\"Create a Range and add it to the calling Collection or Range.\n\n Creates a new Range, adds it to the calling object and returns the newly created Range.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n range = Range(**kwargs)\n if type(self) == Manifest:\n if self.structures:\n self.structures.append(range)\n else:\n self.structures = [range]\n elif type(self) == Range:\n self.add_item(range)\n return range\n
"},{"location":"code/#iiif_prezi3.helpers.make_range.MakeRange.make_range","title":"make_range(**kwargs)
","text":"Create a Range and add it to the calling Collection or Range.
Creates a new Range, adds it to the calling object and returns the newly created Range. Accepts keyword arguments to customize the resulting instance.
Source code in iiif_prezi3/helpers/make_range.py
def make_range(self, **kwargs):\n \"\"\"Create a Range and add it to the calling Collection or Range.\n\n Creates a new Range, adds it to the calling object and returns the newly created Range.\n Accepts keyword arguments to customize the resulting instance.\n \"\"\"\n range = Range(**kwargs)\n if type(self) == Manifest:\n if self.structures:\n self.structures.append(range)\n else:\n self.structures = [range]\n elif type(self) == Range:\n self.add_item(range)\n return range\n
"},{"location":"code/#iiif_prezi3.helpers.make_service","title":"make_service
","text":""},{"location":"code/#iiif_prezi3.helpers.make_service.MakeService","title":"MakeService
","text":"Source code in iiif_prezi3/helpers/make_service.py
class MakeService:\n def make_service(self, id, type, version=3, **kwargs):\n \"\"\"Make a IIIF Prezi service of the desired IIIF API version and adds it to the service list.\n\n Args:\n id (AnyUrl): The id of the service.\n type (str): The type of the service.\n version (int): The API version of the service. Defaults to 3.\n **kwargs (): Arbitrary keyword arguments.\n\n Raises:\n ValueError: If an invalid IIIF API version is provided.\n\n Returns:\n service (Union[ServiceItem, ServiceItem1]): A service instance of the selected version.\n \"\"\"\n serviceversions = {\n 2: ServiceItem1,\n 3: ServiceItem\n }\n if version not in serviceversions:\n raise ValueError(f\"Version: {version} is not a valid IIIF API service version.\")\n service = serviceversions[version](id=id, type=type, **kwargs)\n self.add_service(service)\n return service\n
"},{"location":"code/#iiif_prezi3.helpers.make_service.MakeService.make_service","title":"make_service(id, type, version=3, **kwargs)
","text":"Make a IIIF Prezi service of the desired IIIF API version and adds it to the service list.
Parameters:
Name Type Description Default id
AnyUrl
The id of the service.
required type
str
The type of the service.
required version
int
The API version of the service. Defaults to 3.
3
**kwargs
Arbitrary keyword arguments.
{}
Raises:
Type Description ValueError
If an invalid IIIF API version is provided.
Returns:
Name Type Description service
Union[ServiceItem, ServiceItem1]
A service instance of the selected version.
Source code in iiif_prezi3/helpers/make_service.py
def make_service(self, id, type, version=3, **kwargs):\n \"\"\"Make a IIIF Prezi service of the desired IIIF API version and adds it to the service list.\n\n Args:\n id (AnyUrl): The id of the service.\n type (str): The type of the service.\n version (int): The API version of the service. Defaults to 3.\n **kwargs (): Arbitrary keyword arguments.\n\n Raises:\n ValueError: If an invalid IIIF API version is provided.\n\n Returns:\n service (Union[ServiceItem, ServiceItem1]): A service instance of the selected version.\n \"\"\"\n serviceversions = {\n 2: ServiceItem1,\n 3: ServiceItem\n }\n if version not in serviceversions:\n raise ValueError(f\"Version: {version} is not a valid IIIF API service version.\")\n service = serviceversions[version](id=id, type=type, **kwargs)\n self.add_service(service)\n return service\n
"},{"location":"code/#iiif_prezi3.helpers.set_hwd","title":"set_hwd
","text":""},{"location":"code/#iiif_prezi3.helpers.set_hwd.SetHwd","title":"SetHwd
","text":"Source code in iiif_prezi3/helpers/set_hwd.py
class SetHwd:\n def set_hwd(self, height=None, width=None, duration=None):\n \"\"\"Set the height, width, and duration properties allowing nulls.\n\n Args:\n height (int): The height of the resource or the canvas\n width (int): The width of the resource or the canvas\n duration (float): The duration of the resource\n \"\"\"\n if not (duration or height or width):\n raise TypeError(\"At least one of height, width, or duration must be set\")\n if height and not width:\n raise TypeError(\"width must be set if height is set\")\n if width and not height:\n raise TypeError(\"height must be set if width is set\")\n self.height = height\n self.width = width\n self.duration = duration\n
"},{"location":"code/#iiif_prezi3.helpers.set_hwd.SetHwd.set_hwd","title":"set_hwd(height=None, width=None, duration=None)
","text":"Set the height, width, and duration properties allowing nulls.
Parameters:
Name Type Description Default height
int
The height of the resource or the canvas
None
width
int
The width of the resource or the canvas
None
duration
float
The duration of the resource
None
Source code in iiif_prezi3/helpers/set_hwd.py
def set_hwd(self, height=None, width=None, duration=None):\n \"\"\"Set the height, width, and duration properties allowing nulls.\n\n Args:\n height (int): The height of the resource or the canvas\n width (int): The width of the resource or the canvas\n duration (float): The duration of the resource\n \"\"\"\n if not (duration or height or width):\n raise TypeError(\"At least one of height, width, or duration must be set\")\n if height and not width:\n raise TypeError(\"width must be set if height is set\")\n if width and not height:\n raise TypeError(\"height must be set if width is set\")\n self.height = height\n self.width = width\n self.duration = duration\n
"},{"location":"code/#iiif_prezi3.helpers.set_hwd_from_file","title":"set_hwd_from_file
","text":""},{"location":"code/#iiif_prezi3.helpers.set_hwd_from_file.SetHeightWidthDurationFileHelper","title":"SetHeightWidthDurationFileHelper
","text":"Source code in iiif_prezi3/helpers/set_hwd_from_file.py
class SetHeightWidthDurationFileHelper:\n def set_hwd_from_file(self, file_path_or_object):\n \"\"\"Introspect a file and set the height, width, and duration properties.\n\n Args:\n file_path_or_object (Union[str, fp]): the file path or file object to introspect\n \"\"\"\n if isinstance(file_path_or_object, str) or isinstance(file_path_or_object, os.PathLike):\n filetype, _ = mimetypes.guess_type(file_path_or_object)\n if not filetype.startswith(\"image/\"):\n raise NotImplementedError\n\n tmp_image = Image.open(file_path_or_object)\n w, h = tmp_image.size\n self.set_hwd(h, w, None)\n tmp_image.close()\n
"},{"location":"code/#iiif_prezi3.helpers.set_hwd_from_file.SetHeightWidthDurationFileHelper.set_hwd_from_file","title":"set_hwd_from_file(file_path_or_object)
","text":"Introspect a file and set the height, width, and duration properties.
Parameters:
Name Type Description Default file_path_or_object
Union[str, fp]
the file path or file object to introspect
required Source code in iiif_prezi3/helpers/set_hwd_from_file.py
def set_hwd_from_file(self, file_path_or_object):\n \"\"\"Introspect a file and set the height, width, and duration properties.\n\n Args:\n file_path_or_object (Union[str, fp]): the file path or file object to introspect\n \"\"\"\n if isinstance(file_path_or_object, str) or isinstance(file_path_or_object, os.PathLike):\n filetype, _ = mimetypes.guess_type(file_path_or_object)\n if not filetype.startswith(\"image/\"):\n raise NotImplementedError\n\n tmp_image = Image.open(file_path_or_object)\n w, h = tmp_image.size\n self.set_hwd(h, w, None)\n tmp_image.close()\n
"},{"location":"code/#iiif_prezi3.helpers.set_hwd_from_iiif","title":"set_hwd_from_iiif
","text":""},{"location":"code/#iiif_prezi3.helpers.set_hwd_from_iiif.SetHwdFromIIIF","title":"SetHwdFromIIIF
","text":"Source code in iiif_prezi3/helpers/set_hwd_from_iiif.py
class SetHwdFromIIIF:\n # should probably be added to canvas helpers\n\n def set_hwd_from_iiif(self, url):\n \"\"\"Set height and width on a Canvas object.\n\n Requests IIIF Image information remotely for an\n image resource and sets resulting height and width.\n This method will return the info.json\n\n Args:\n url (str): An HTTP URL for the IIIF image endpoint.\n \"\"\"\n # resource url may or may not end with info.json;\n # add if not present\n if not url.endswith(\"info.json\"):\n url = f\"{ url.rstrip('/') }/info.json\"\n\n response = requests.get(url)\n # if response is not 200, raise exception\n if response.status_code != requests.codes.ok:\n response.raise_for_status()\n # if response is not valid json, request will raise\n # requests.exceptions.JSONDecodeError\n # \u2014\u00a0handle or document and let calling code handle?\n resource_info = response.json()\n self.set_hwd(resource_info.get(\"height\"), resource_info.get(\"width\"))\n\n return resource_info\n
"},{"location":"code/#iiif_prezi3.helpers.set_hwd_from_iiif.SetHwdFromIIIF.set_hwd_from_iiif","title":"set_hwd_from_iiif(url)
","text":"Set height and width on a Canvas object.
Requests IIIF Image information remotely for an image resource and sets resulting height and width. This method will return the info.json
Parameters:
Name Type Description Default url
str
An HTTP URL for the IIIF image endpoint.
required Source code in iiif_prezi3/helpers/set_hwd_from_iiif.py
def set_hwd_from_iiif(self, url):\n \"\"\"Set height and width on a Canvas object.\n\n Requests IIIF Image information remotely for an\n image resource and sets resulting height and width.\n This method will return the info.json\n\n Args:\n url (str): An HTTP URL for the IIIF image endpoint.\n \"\"\"\n # resource url may or may not end with info.json;\n # add if not present\n if not url.endswith(\"info.json\"):\n url = f\"{ url.rstrip('/') }/info.json\"\n\n response = requests.get(url)\n # if response is not 200, raise exception\n if response.status_code != requests.codes.ok:\n response.raise_for_status()\n # if response is not valid json, request will raise\n # requests.exceptions.JSONDecodeError\n # \u2014\u00a0handle or document and let calling code handle?\n resource_info = response.json()\n self.set_hwd(resource_info.get(\"height\"), resource_info.get(\"width\"))\n\n return resource_info\n
"},{"location":"code/#iiif_prezi3.helpers.to_reference","title":"to_reference
","text":""},{"location":"code/#iiif_prezi3.helpers.to_reference.ToReference","title":"ToReference
","text":"Source code in iiif_prezi3/helpers/to_reference.py
class ToReference:\n\n def to_reference(self):\n \"\"\"Returns a Reference object that points to the calling object.\"\"\"\n # Only try to set thumbnail if it's a Class that can have one\n if isinstance(self, (Collection, Manifest, Canvas, AnnotationPage, Annotation, AnnotationCollection, Range)):\n thumbnail = self.thumbnail\n else:\n thumbnail = None\n\n # Currently the skeleton Reference requires a label, but some Referenceable objects may not have one (e.g AnnotationPage)\n # TODO: Remove this when the Schema is updated to have different reference types\n if not self.label:\n self.label = \"\"\n\n # Ensure that we use a specific Reference type if it exists\n if isinstance(self, Manifest):\n target_type = ManifestRef\n elif isinstance(self, Collection):\n target_type = CollectionRef\n elif isinstance(self, Canvas):\n target_type = CanvasRef\n elif isinstance(self, Range):\n target_type = RangeRef\n else:\n target_type = Reference\n\n return target_type(id=self.id, label=self.label, type=self.type, thumbnail=thumbnail)\n
"},{"location":"code/#iiif_prezi3.helpers.to_reference.ToReference.to_reference","title":"to_reference()
","text":"Returns a Reference object that points to the calling object.
Source code in iiif_prezi3/helpers/to_reference.py
def to_reference(self):\n \"\"\"Returns a Reference object that points to the calling object.\"\"\"\n # Only try to set thumbnail if it's a Class that can have one\n if isinstance(self, (Collection, Manifest, Canvas, AnnotationPage, Annotation, AnnotationCollection, Range)):\n thumbnail = self.thumbnail\n else:\n thumbnail = None\n\n # Currently the skeleton Reference requires a label, but some Referenceable objects may not have one (e.g AnnotationPage)\n # TODO: Remove this when the Schema is updated to have different reference types\n if not self.label:\n self.label = \"\"\n\n # Ensure that we use a specific Reference type if it exists\n if isinstance(self, Manifest):\n target_type = ManifestRef\n elif isinstance(self, Collection):\n target_type = CollectionRef\n elif isinstance(self, Canvas):\n target_type = CanvasRef\n elif isinstance(self, Range):\n target_type = RangeRef\n else:\n target_type = Reference\n\n return target_type(id=self.id, label=self.label, type=self.type, thumbnail=thumbnail)\n
"},{"location":"generate-schema/","title":"Generating the Schema","text":"Install the datamodl-codegen program which will convert a JSON schema into python code. Either follow the instructions here or run:
pip install datamodel-code-generator\n
Then in the iiif-prezi3 code directory run:
datamodel-codegen --input ../../iiif/presentation-validator/schema/iiif_3_0.json --input-file-type jsonschema --use-default --base-class base.Base --output skeleton.py\n
Replacing the path to your iiif schema file with where ever you have downloaded the iiif_3_0.json file.
"},{"location":"getting-started-using-iiifprezi3-without-helpermethods/","title":"Getting started: using iiifprezi3 without helper methods","text":"Note
iiif-prezi3
offers useful helper methods for adding IIIF resources, it is preferable to use them when possible.
For special needs, not addressed by the helper methods, users may take advantage directly of the Python classes generated by datamodel-code-generator. These classes can be used for generating instances of IIIF objects described in the presentation API v.3.
In the following lines of code, we will create a manifest and two canvases using directly the pydantic classes:
import iiif_prezi3\namanifest = iiif_prezi3.Manifest(id='http://iiif.example.org/prezi/Manifest/0', label={'en': ['default label']})\nacanvas = iiif_prezi3.Canvas(id='http://iiif.example.org/prezi/Manifest/0/canvas/01', label={'en': ['default label']})\nasecondcanvas = iiif_prezi3.Canvas(id='http://iiif.example.org/prezi/Manifest/0/canvas/02', label={'en': ['second label']})\n
For constructing nested objects we have to assign to the items property a list containing the valid IIIF objects accepted by the class:
amanifest.items = [acanvas,asecondcanvas]\n
If we try to set the items property of the manifest items to a string pydantic
will rise a ValidationError
:
amanifest.items = [\"this shouldn't be here\"]\n
Warning
Be aware that appending to the items list after that the items property has been assigned :
amanifest.items.append(\"this shouldn't be here\")\n
will not raise any error regarding the input.
print(amanifest.json(exclude_unset=True,indent=2))\n
{\n \"id\": \"http://iiif.example.org/prezi/Manifest/0\",\n \"type\": \"Manifest\",\n \"label\": {},\n \"items\": [\n {\n \"id\": \"http://iiif.example.org/prezi/Manifest/0/canvas/01\",\n \"type\": \"Canvas\",\n \"label\": {}\n },\n {\n \"id\": \"http://iiif.example.org/prezi/Manifest/0/canvas/02\",\n \"type\": \"Canvas\",\n \"label\": {}\n },\n \"this shouldn't be here\"\n ]\n}\n
Of course, in most of the use cases, canvases will be created dynamically so a possible approach for constructing the manifest can be the following:
canvases = []\nfor i in range(3):\n canvasid = f'http://iiif.example.org/prezi/CanvasID/{i}'\n aservice = {\n \"id\": \"https://example.org/iiif/book1/page2\",\n \"type\": \"ImageService3\",\n \"profile\": \"level2\"\n }\n anannotation = iiif_prezi3.Annotation(type='Annotation',id=canvasid+'/annotation/0',target=canvasid)\n anannotation.motivation = 'painting'\n # aresource = Resource(service=[aservice],type='Resource')\n anannotation.body = iiif_prezi3.ResourceItem(service=[aservice],id=canvasid+'/annotation/resource',type='Image')\n anannotationpage = iiif_prezi3.AnnotationPage(type='AnnotationPage')\n anannotationpage.items = [anannotation]\n acanvas.items = [anannotationpage]\n canvases.append(acanvas)\n\namanifest.items = canvases\n
Notice that the canvases list is created at the beginning but is assigned to the items property of the manifest only once at the end, in this way pydantic will validate the list.
Warning
Keep in mind that objects contained in the canvases
list are references in the manifest items, hence any modification on the original object will affect the object inside the manifest. This holds true for any object added to the model.
"},{"location":"write-helper-method/","title":"Helper methods","text":"Helper methods in iiif-prezi3
allow functionality for common use cases to be included in the package. Helpers that are general can be loaded and used by the user as required, and those that target specific schema objects (e.g a helper to add a Canvas to a Manifest) are monkeypatched onto the relevant schema class at load time.
"},{"location":"write-helper-method/#location-and-structure","title":"Location and structure","text":"Helper methods should be located in Python files inside the helpers/
directory. Direct helper methods that take schema objects as arguments can be singular functions, whereas those which are designed to add new functions or properties to existing schema classes must themselves be containing inside a class, to enable them to be monkeypatched in correctly.
"},{"location":"write-helper-method/#accessing-schema-objects","title":"Accessing Schema Objects","text":"Relevant schema classes can be loaded from the skeleton.py
file in the main iiif-prezi3
package by using a relative import:
from ..skeleton import Manifest\n
"},{"location":"write-helper-method/#monkeypatching-onto-schema-classes","title":"Monkeypatching onto Schema classes","text":"If the helper targets a class from the main IIIF Presentation 3 schema, then it can be monkeypatched onto that class at runtime using the iiif_prezi3.loader.monkeypatch_schema()
method. This function takes two arguments: the class to target, and the class(es) containing the helper methods, either as a single object or a list. Add the monkeypatch function call at the end of your helper file, and it will be run when the helper file is imported by the main package (as detailed below).
from ..skeleton import Manifest\nfrom ..loader import monkeypatch_schema\n\n\nclass MyHelper:\n def helper_function(self):\n return \"I am a Manifest helper\"\n\nmonkeypatch_schema(Manifest, MyHelper)\n
"},{"location":"write-helper-method/#including-helpers-in-the-main-package","title":"Including helpers in the main package","text":"To enable a helper, import it via relative import in the helpers/__init__.py
file. This will include the functions directly in the namespace of iiif_prezi3.helpers
, which in turn is imported in its entirety by the __init__.py
file of the main package.
In helpers/__init__.py
:
from .example_helper import MyHelper\n
Allowing:
>>> from iiif_prezi3 import Manifest\n>>> m = Manifest(id=\"https://example.com/manifest\", type=\"Manifest\", label={\"en\":\"Example Manifest\"})\n>>> m.helper_function()\n'I am a Manifest helper'\n
"},{"location":"recipes/","title":"Cookbook Recipes","text":"This section of the documentation attempts to provide a \"learn by example\" resource, by reproducing the IIIF Cookbook recipes using the iiif-prezi3
library.
Where possible, the helper methods and other conveniences of iiif-prezi3
are leveraged, with secondary examples showing alternate methods of creating the recipe JSON.
If you would like to contribute to this section, please see the Cookbook recipe examples issue in the project's GitHub repository.
"},{"location":"recipes/0001-mvm-image/","title":"Simplest Manifest - Single Image File","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0001-mvm-image/ JSON-LD: https://iiif.io/api/cookbook/recipe/0001-mvm-image/manifest.json"},{"location":"recipes/0001-mvm-image/#method-1-using-the-make_canvas-and-add_image-helpers","title":"Method 1 - Using the make_canvas
and add_image
helpers","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0001-mvm-image\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\", label=\"Single Image Example\")\ncanvas = manifest.make_canvas(id=f\"{base_url}/canvas/p1\", height=1800, width=1200)\nanno_page = canvas.add_image(image_url=\"http://iiif.io/api/presentation/2.1/example/fixtures/resources/page1-full.png\",\n anno_page_id=f\"{base_url}/page/p1/1\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n format=\"image/png\",\n height=1800,\n width=1200\n )\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0001-mvm-image/#method-2-building-the-structure-manually-and-using-the-add_item-helper","title":"Method 2 - Building the structure manually and using the add_item
helper","text":"from iiif_prezi3 import Manifest, Canvas, AnnotationPage, Annotation, ResourceItem, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0001-mvm-image\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\", label=\"Single Image Example\")\ncanvas = Canvas(id=f\"{base_url}/canvas/p1\", height=1800, width=1200)\nanno_body = ResourceItem(id=\"http://iiif.io/api/presentation/2.1/example/fixtures/resources/page1-full.png\",\n type=\"Image\",\n format=\"image/png\",\n height=1800,\n width=1200)\nanno_page = AnnotationPage(id=f\"{base_url}/page/p1/1\")\nanno = Annotation(id=f\"{base_url}/annotation/p0001-image\",\n motivation=\"painting\",\n body=anno_body,\n target=canvas.id)\nanno_page.add_item(anno)\ncanvas.add_item(anno_page)\nmanifest.add_item(canvas)\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0002-mvm-audio/","title":"Simplest Manifest - Audio","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0002-mvm-audio/ JSON-LD: https://iiif.io/api/cookbook/recipe/0002-mvm-audio/manifest.json"},{"location":"recipes/0002-mvm-audio/#method-1-building-the-structure-and-using-the-add_item-helper","title":"Method 1 - Building the structure and using the add_item
helper","text":"from iiif_prezi3 import Manifest, AnnotationPage, Annotation, ResourceItem, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0002-mvm-audio\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\", label=\"Simplest Audio Example 1\")\ncanvas = manifest.make_canvas(id=f\"{base_url}/canvas\", duration=1985.024)\nanno_body = ResourceItem(id=\"https://fixtures.iiif.io/audio/indiana/mahler-symphony-3/CD1/medium/128Kbps.mp4\",\n type=\"Sound\",\n format=\"audio/mp4\",\n duration=1985.024)\nanno_page = AnnotationPage(id=f\"{base_url}/canvas/page\")\nanno = Annotation(id=f\"{base_url}/canvas/page/annotation\",\n motivation=\"painting\",\n body=anno_body,\n target=canvas.id)\nanno_page.add_item(anno)\ncanvas.add_item(anno_page)\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0003-mvm-video/","title":"Simplest Manifest - Video","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0003-mvm-video/ JSON-LD: https://iiif.io/api/cookbook/recipe/0003-mvm-video/manifest.json"},{"location":"recipes/0003-mvm-video/#method-1-building-the-structure-manually-and-using-the-add_item-helper","title":"Method 1 - Building the structure manually and using the add_item
helper","text":"from iiif_prezi3 import Manifest, AnnotationPage, Annotation, ResourceItem, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0003-mvm-video\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\", label=\"Video Example 3\")\ncanvas = manifest.make_canvas(id=f\"{base_url}/canvas\")\nanno_body = ResourceItem(id=\"https://fixtures.iiif.io/video/indiana/lunchroom_manners/high/lunchroom_manners_1024kb.mp4\",\n type=\"Video\",\n format=\"video/mp4\")\nanno_page = AnnotationPage(id=f\"{base_url}/canvas/page\")\nanno = Annotation(id=f\"{base_url}/canvas/page/annotation\",\n motivation=\"painting\",\n body=anno_body,\n target=canvas.id)\n\nhwd = {\"height\": 360, \"width\": 480, \"duration\": 572.034}\nanno_body.set_hwd(**hwd)\ncanvas.set_hwd(**hwd)\n\nanno_page.add_item(anno)\ncanvas.add_item(anno_page)\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0004-canvas-size/","title":"Image and Canvas with Differing Dimensions","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0004-canvas-size/ JSON-LD: https://iiif.io/api/cookbook/recipe/0004-canvas-size/manifest.json"},{"location":"recipes/0004-canvas-size/#method-1-using-the-set_hwd-helper","title":"Method 1 - Using the set_hwd
helper","text":"from iiif_prezi3 import Manifest, AnnotationPage, Annotation, ResourceItem, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0004-canvas-size\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\", label=\"Still image from an opera performance at Indiana University\")\ncanvas = manifest.make_canvas(id=f\"{base_url}/canvas/p1\")\nanno_body = ResourceItem(id=\"https://fixtures.iiif.io/video/indiana/donizetti-elixir/act1-thumbnail.png\",\n type=\"Image\",\n format=\"image/png\")\nanno_page = AnnotationPage(id=f\"{base_url}/page/p1/1\")\nanno = Annotation(id=f\"{base_url}/annotation/p0001-image\",\n motivation=\"painting\",\n body=anno_body,\n target=canvas.id)\n\nanno_body.set_hwd(height=360, width=640)\ncanvas.set_hwd(height=1080, width=1920)\n\nanno_page.add_item(anno)\ncanvas.add_item(anno_page)\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0005-image-service/","title":"Support Deep Viewing with Basic Use of a IIIF Image Service","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0005-image-service/ JSON-LD: https://iiif.io/api/cookbook/recipe/0005-image-service/manifest.json"},{"location":"recipes/0005-image-service/#method-1-using-the-make_canvas_from_iiif-helper","title":"Method 1 - Using the make_canvas_from_iiif
helper","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0005-image-service\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\", label=\"Picture of G\u00f6ttingen taken during the 2019 IIIF Conference\")\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/918ecd18c2592080851777620de9bcb5-gottingen\",\n id=f\"{base_url}/canvas/p1\",\n label=\"Canvas with a single IIIF image\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0006-text-language/","title":"Internationalization and Multi-language Values","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0006-text-language/ JSON-LD: https://iiif.io/api/cookbook/recipe/0006-text-language/manifest.json"},{"location":"recipes/0006-text-language/#method-1-construct-the-language-dictionaries-during-object-creation","title":"Method 1 - Construct the language dictionaries during object creation","text":"from iiif_prezi3 import Manifest, KeyValueString\n\nbase_url = \"https://iiif.io/api/cookbook/recipe/0006-text-language\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\",\n label={\"en\": [\"Whistler's Mother\"], \"fr\": [\"La M\u00e8re de Whistler\"]})\nmanifest.metadata = [\n KeyValueString(label={\"en\": [\"Creator\"], \"fr\": [\"Auteur\"]}, value=\"Whistler, James Abbott McNeill\"),\n KeyValueString(label={\"en\": [\"Subject\"], \"fr\": [\"Sujet\"]},\n value={\"en\": [\"McNeill Anna Matilda, mother of Whistler (1804-1881)\"],\n \"fr\": [\"McNeill Anna Matilda, m\u00e8re de Whistler (1804-1881)\"]})\n]\nmanifest.summary = {\"en\": [\"Arrangement in Grey and Black No. 1, also called Portrait of the Artist's Mother.\"],\n \"fr\": [\"Arrangement en gris et noir n\u00b01, also called Portrait de la m\u00e8re de l'artiste.\"]}\nmanifest.requiredStatement = KeyValueString(label={\"en\": [\"Held By\"], \"fr\": [\"D\u00e9tenu par\"]}, value=\"Mus\u00e9e d'Orsay, Paris, France\")\n\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/329817fc8a251a01c393f517d8a17d87-Whistlers_Mother\",\n id=f\"{base_url}/canvas/p1\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0007-string-formats/","title":"Embedding HTML in descriptive properties","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0007-string-formats/ JSON-LD: https://iiif.io/api/cookbook/recipe/0007-string-formats/manifest.json"},{"location":"recipes/0007-string-formats/#method-1-building-the-object-directly-and-making-use-of-the-autolang-config","title":"Method 1 - Building the object directly and making use of the AutoLang config","text":"from iiif_prezi3 import Manifest, KeyValueString, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0007-string-formats\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\",\n label=\"Picture of G\u00f6ttingen taken during the 2019 IIIF Conference\",\n summary=\"<p>Picture taken by the <a href=\\\"https://github.com/glenrobson\\\">IIIF Technical Coordinator</a></p>\",\n rights=\"http://creativecommons.org/licenses/by-sa/3.0/\",\n requiredStatement=KeyValueString(label=\"Attribution\",\n value=\"<span>Glen Robson, IIIF Technical Coordinator. <a href=\\\"https://creativecommons.org/licenses/by-sa/3.0\\\">CC BY-SA 3.0</a> <img src=\\\"https://licensebuttons.net/l/by-sa/3.0/88x31.png\\\"/></span>\"),\n metadata=[KeyValueString(label=\"Author\", value={\"none\": [\"<span><a href='https://github.com/glenrobson'>Glen Robson</a></span>\"]})])\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/918ecd18c2592080851777620de9bcb5-gottingen\",\n id=f\"{base_url}/canvas/p1\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0008-rights/","title":"Rights statement","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0008-rights/ JSON-LD: https://iiif.io/api/cookbook/recipe/0008-rights/manifest.json"},{"location":"recipes/0008-rights/#method-1-building-the-object-directly-and-making-use-of-the-autolang-config","title":"Method 1 - Building the object directly and making use of the AutoLang config","text":"from iiif_prezi3 import Manifest, KeyValueString, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0008-rights\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\",\n label=\"Picture of G\u00f6ttingen taken during the 2019 IIIF Conference\",\n summary=\"<p>Picture taken by the <a href=\\\"https://github.com/glenrobson\\\">IIIF Technical Coordinator</a></p>\",\n rights=\"http://creativecommons.org/licenses/by-sa/3.0/\",\n requiredStatement=KeyValueString(label=\"Attribution\",\n value=\"<span>Glen Robson, IIIF Technical Coordinator. <a href=\\\"https://creativecommons.org/licenses/by-sa/3.0\\\">CC BY-SA 3.0</a> <a href=\\\"https://creativecommons.org/licenses/by-sa/3.0\\\" title=\\\"CC BY-SA 3.0\\\"><img src=\\\"https://licensebuttons.net/l/by-sa/3.0/88x31.png\\\"/></a></span>\")\n )\n\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/918ecd18c2592080851777620de9bcb5-gottingen\",\n id=f\"{base_url}/canvas/p1\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0009-book-1/","title":"Simple Manifest - Book","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0009-book-1/ JSON-LD: https://iiif.io/api/cookbook/recipe/0009-book-1/manifest.json"},{"location":"recipes/0009-book-1/#method-1-setting-the-behavior-property-during-object-construction","title":"Method 1 - Setting the behavior
property during object construction","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0009-book-1\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\",\n label=\"Simple Manifest - Book\",\n behavior=[\"paged\"])\ncanvas1 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f18\",\n id=f\"{base_url}/canvas/p1\",\n label=\"Blank page\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\ncanvas2 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f19\",\n id=f\"{base_url}/canvas/p2\",\n label=\"Frontispiece\",\n anno_id=f\"{base_url}/annotation/p0002-image\",\n anno_page_id=f\"{base_url}/page/p2/1\")\n\ncanvas3 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f20\",\n id=f\"{base_url}/canvas/p3\",\n label=\"Title page\",\n anno_id=f\"{base_url}/annotation/p0003-image\",\n anno_page_id=f\"{base_url}/page/p3/1\")\n\ncanvas4 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f21\",\n id=f\"{base_url}/canvas/p4\",\n label=\"Blank page\",\n anno_id=f\"{base_url}/annotation/p0004-image\",\n anno_page_id=f\"{base_url}/page/p4/1\")\n\ncanvas5 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f22\",\n id=f\"{base_url}/canvas/p5\",\n label=\"Bookplate\",\n anno_id=f\"{base_url}/annotation/p0005-image\",\n anno_page_id=f\"{base_url}/page/p5/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0010-book-2-viewing-direction/","title":"Viewing direction and Its Effect on Navigation","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0010-book-2-viewing-direction/ JSON-LD Example 1: https://iiif.io/api/cookbook/recipe/0010-book-2-viewing-direction/manifest-rtl.json JSON-LD Example 2: https://iiif.io/api/cookbook/recipe/0010-book-2-viewing-direction/manifest-ttb.json"},{"location":"recipes/0010-book-2-viewing-direction/#method-1-setting-the-viewingdirection-property-during-object-construction","title":"Method 1 - Setting the viewingDirection
property during object construction","text":""},{"location":"recipes/0010-book-2-viewing-direction/#example-1","title":"Example 1","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0010-book-2-viewing-direction\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest-rtl.json\",\n label=\"Book with Right-to-Left Viewing Direction\",\n summary=\"Playbill for \\\"Akiba gongen kaisen-banashi,\\\" \\\"Futatsu ch\u014dch\u014d kuruwa nikki\\\" and \\\"Godairiki koi no f\u016bjime\\\" performed at the Chikugo Theater in Osaka from the fifth month of Kaei 2 (May, 1849); main actors: Gad\u014d Kataoka II, Ebiz\u014d Ichikawa VI, Kit\u014d Sawamura II, Daigor\u014d Mimasu IV and Karoku Nakamura I; on front cover: producer Mominosuke Ichikawa's crest.\",\n viewingDirection=\"right-to-left\")\n\ncanvas1 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/4f92cceb12dd53b52433425ce44308c7-ucla_bib1987273_no001_rs_001\",\n id=f\"{base_url}/canvas/p1\",\n label=\"front cover\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\ncanvas2 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/4f92cceb12dd53b52433425ce44308c7-ucla_bib1987273_no001_rs_002\",\n id=f\"{base_url}/canvas/p2\",\n label=\"pages 1\u20132\",\n anno_id=f\"{base_url}/annotation/p0002-image\",\n anno_page_id=f\"{base_url}/page/p2/1\")\n\ncanvas3 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/4f92cceb12dd53b52433425ce44308c7-ucla_bib1987273_no001_rs_003\",\n id=f\"{base_url}/canvas/p3\",\n label=\"pages 3\u20134\",\n anno_id=f\"{base_url}/annotation/p0003-image\",\n anno_page_id=f\"{base_url}/page/p3/1\")\n\ncanvas4 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/4f92cceb12dd53b52433425ce44308c7-ucla_bib1987273_no001_rs_004\",\n id=f\"{base_url}/canvas/p4\",\n label=\"pages 5\u20136\",\n anno_id=f\"{base_url}/annotation/p0004-image\",\n anno_page_id=f\"{base_url}/page/p4/1\")\n\ncanvas5 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/4f92cceb12dd53b52433425ce44308c7-ucla_bib1987273_no001_rs_005\",\n id=f\"{base_url}/canvas/p5\",\n label=\"back cover\",\n anno_id=f\"{base_url}/annotation/p0005-image\",\n anno_page_id=f\"{base_url}/page/p5/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0010-book-2-viewing-direction/#example-2","title":"Example 2","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0010-book-2-viewing-direction\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest-ttb.json\",\n label=\"Diary with Top-to-Bottom Viewing Direction\",\n summary=\"William Lewis Sachtleben was an American long-distance cyclist who rode across Asia from Istanbul to Peking in 1891 to 1892 with Thomas Gaskell Allen Jr., his classmate from Washington University. This was part of a longer journey that began the day after they had graduated from college, when they travelled to New York and on to Liverpool; in all they travelled 15,044 miles by bicycle, 'the longest continuous land journey ever made around the world' as reported in their book <cite>Across Asia on a bicycle</cite> (1895). Sachtleben documented his travels with photographs and diaries, the latter of which he numbered sequentially. The diary of notebook 'No. 10' covers a portion of their journey through the Armenian area of Turkey from April 12 to May 9 (there is a 2-page reading list at the end). During this time they rode from Ankara (Angora in the diary) to Sivas, where they stayed for ten days while Allen had a bout of typhoid fever, and the first half of a ten-day excursion to Merzifon (Mersovan in the diary), taken by Sachtleben to give Allen additional time to recover.\",\n viewingDirection=\"top-to-bottom\")\ncanvas1 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/9ee11092dfd2782634f5e8e2c87c16d5-uclamss_1841_diary_07_02\",\n id=f\"{base_url}/canvas/v1\",\n label=\"image 1\",\n anno_id=f\"{base_url}/annotation/v0001-image\",\n anno_page_id=f\"{base_url}/page/v1/1\")\n\ncanvas2 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/9ee11092dfd2782634f5e8e2c87c16d5-uclamss_1841_diary_07_03\",\n id=f\"{base_url}/canvas/v2\",\n label=\"image 2\",\n anno_id=f\"{base_url}/annotation/v0002-image\",\n anno_page_id=f\"{base_url}/page/v2/1\")\n\ncanvas3 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/9ee11092dfd2782634f5e8e2c87c16d5-uclamss_1841_diary_07_04\",\n id=f\"{base_url}/canvas/v3\",\n label=\"image 3\",\n anno_id=f\"{base_url}/annotation/v0003-image\",\n anno_page_id=f\"{base_url}/page/v3/1\")\n\ncanvas4 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/9ee11092dfd2782634f5e8e2c87c16d5-uclamss_1841_diary_07_05\",\n id=f\"{base_url}/canvas/v4\",\n label=\"image 4\",\n anno_id=f\"{base_url}/annotation/v0004-image\",\n anno_page_id=f\"{base_url}/page/v4/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0011-book-3-behavior/","title":"Book 'behavior' Variations (continuous, individuals)","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0011-book-3-behavior/ JSON-LD Use Case 1: https://iiif.io/api/cookbook/recipe/0011-book-3-behavior/manifest-continuous.json JSON-LD Use Case 2: https://iiif.io/api/cookbook/recipe/0011-book-3-behavior/manifest-individuals.json"},{"location":"recipes/0011-book-3-behavior/#method-1-setting-the-behavior-property-during-object-construction","title":"Method 1 - Setting the behavior
property during object construction","text":""},{"location":"recipes/0011-book-3-behavior/#use-case-1","title":"Use Case 1","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0011-book-3-behavior\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest-continuous.json\",\n label={\"gez\": [\"Ms. 21 M\u0101zemur\u0101 D\u0101wit, Asmat [\u1218\u12dd\u1219\u1228 \u12f3\u12ca\u1275]\"]},\n behavior=[\"continuous\"])\ncanvas1 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/8c169124171e6b2253b698a22a938f07-21198-zz001hbmd9_1300412_master\",\n id=f\"{base_url}/canvas/s1\",\n label=\"Section 1 [Recto]\",\n anno_id=f\"{base_url}/annotation/s0001-image\",\n anno_page_id=f\"{base_url}/page/s1/1\")\n\ncanvas2 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/8c169124171e6b2253b698a22a938f07-21198-zz001hbmft_1300418_master\",\n id=f\"{base_url}/canvas/s2\",\n label=\"Section 2 [Recto]\",\n anno_id=f\"{base_url}/annotation/s0002-image\",\n anno_page_id=f\"{base_url}/page/s2/1\")\n\ncanvas3 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/8c169124171e6b2253b698a22a938f07-21198-zz001hbmgb_1300426_master\",\n id=f\"{base_url}/canvas/s3\",\n label=\"Section 3 [Recto]\",\n anno_id=f\"{base_url}/annotation/s0003-image\",\n anno_page_id=f\"{base_url}/page/s3/1\")\n\ncanvas4 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/8c169124171e6b2253b698a22a938f07-21198-zz001hbmhv_1300436_master\",\n id=f\"{base_url}/canvas/s4\",\n label=\"Section 4 [Recto]\",\n anno_id=f\"{base_url}/annotation/s0004-image\",\n anno_page_id=f\"{base_url}/page/s4/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0011-book-3-behavior/#use-case-2","title":"Use Case 2","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0011-book-3-behavior\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest-individuals.json\",\n label={\"ca\": [\"[Conoximent de las orines] Ihesus, Ihesus. En nom de Deu et dela beneyeta sa mare e de tots los angels i archangels e de tots los sants e santes de paradis yo micer Johannes comense aquest libre de reseptes en l\u2019ayn Mi 466.\"]},\n behavior=[\"individuals\"])\n\ncanvas1 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/85a96c630f077e6ac6cb984f1b752bbf-0-21198-zz00022840-1-master\",\n id=f\"{base_url}/canvas/v1\",\n label=\"inside cover; 1r\",\n anno_id=f\"{base_url}/annotation/v0001-image\",\n anno_page_id=f\"{base_url}/page/v1/1\")\n\ncanvas2 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/85a96c630f077e6ac6cb984f1b752bbf-1-21198-zz00022882-1-master\",\n id=f\"{base_url}/canvas/v2\",\n label=\"2v, 3r\",\n anno_id=f\"{base_url}/annotation/v0002-image\",\n anno_page_id=f\"{base_url}/page/v2/1\")\n\ncanvas3 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/85a96c630f077e6ac6cb984f1b752bbf-2-21198-zz000228b3-1-master\",\n id=f\"{base_url}/canvas/v3\",\n label=\"3v, 4r\",\n anno_id=f\"{base_url}/annotation/v0003-image\",\n anno_page_id=f\"{base_url}/page/v3/1\")\n\ncanvas4 = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/85a96c630f077e6ac6cb984f1b752bbf-3-21198-zz000228d4-1-master\",\n id=f\"{base_url}/canvas/v4\",\n label=\"4v, 5r\",\n anno_id=f\"{base_url}/annotation/v0004-image\",\n anno_page_id=f\"{base_url}/page/v4/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0014-accompanyingcanvas/","title":"\"Audio Presentation with Accompanying Image\"","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0014-accompanyingcanvas/ JSON-LD: https://iiif.io/api/cookbook/recipe/0014-accompanyingcanvas/manifest.json"},{"location":"recipes/0014-accompanyingcanvas/#method-1-use-accompanyingcanvas-and-add_item-helper","title":"Method 1 - Use AccompanyingCanvas and add_item() helper","text":"from iiif_prezi3 import Manifest, ResourceItem, AnnotationPage, Annotation, config, AccompanyingCanvas\n\nbase_url = \"https://iiif.io/api/cookbook/recipe/0014-accompanyingcanvas\"\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\naccompanying_canvas = AccompanyingCanvas(\n id=f\"{base_url}/canvas/accompanying\",\n label=\"First page of score for Gustav Mahler, Symphony No. 3\",\n height=998,\n width=772,\n)\nmanifest = Manifest(\n id=f\"{base_url}/manifest.json\",\n label=\"Partial audio recording of Gustav Mahler's _Symphony No. 3_\",\n)\nac_anno_body = ResourceItem(\n id=\"https://iiif.io/api/image/3.0/example/reference/4b45bba3ea612ee46f5371ce84dbcd89-mahler-0/full/,998/0/default.jpg\",\n type=\"Image\",\n format=\"image/jpeg\",\n height=998,\n width=772,\n)\nac_anno_body.make_service(\n id=\"https://iiif.io/api/image/3.0/example/reference/4b45bba3ea612ee46f5371ce84dbcd89-mahler-0\",\n type=\"ImageService3\",\n profile=\"level1\"\n)\nac_anno_page = AnnotationPage(\n id=f\"{base_url}/canvas/accompanying/annotation/page\"\n)\nac_anno = Annotation(\n id=f\"{base_url}/canvas/accompanying/annotation/image\",\n motivation=\"painting\",\n body=ac_anno_body,\n target=f\"{base_url}/canvas/accompanying\"\n)\nac_anno_page.add_item(ac_anno)\naccompanying_canvas.add_item(ac_anno_page)\ncanvas = manifest.make_canvas(\n id=f\"{base_url}/canvas/p1\",\n label=\"Gustav Mahler, Symphony No. 3, CD 1\",\n duration=1985.024,\n accompanyingCanvas=accompanying_canvas\n)\nanno_body = ResourceItem(\n id=\"https://fixtures.iiif.io/audio/indiana/mahler-symphony-3/CD1/medium/128Kbps.mp4\",\n type=\"Sound\",\n format=\"video/mp4\",\n duration=1985.024,\n)\nanno_page = AnnotationPage(\n id=f\"{base_url}/canvas/page/p1\"\n)\nanno = Annotation(\n id=f\"{base_url}/canvas/page/annotation/segment1-audio\",\n motivation=\"painting\",\n body=anno_body,\n target=canvas.id\n)\nanno_page.add_item(anno)\ncanvas.add_item(anno_page)\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0015-start/","title":"Begin playback at a specific point - Time-based media","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0015-start/ JSON-LD: https://iiif.io/api/cookbook/recipe/0015-start/manifest.json"},{"location":"recipes/0015-start/#method-1-building-the-start-structure-using-the-specificresource-class","title":"Method 1 - Building the start
structure using the SpecificResource
class","text":"from iiif_prezi3 import Manifest, KeyValueString, ResourceItem, AnnotationPage, Annotation, SpecificResource, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0015-start\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\",\n label=\"Video of a 30-minute digital clock\",\n rights=\"http://creativecommons.org/licenses/by/3.0/\",\n requiredStatement=KeyValueString(label=\"Attribution\",\n value=\"<span>The video was created by <a href='https://www.youtube.com/watch?v=Lsq0FiXjGHg'>DrLex1</a> and was released using a <a href='https://creativecommons.org/licenses/by/3.0/'>Creative Commons Attribution license</a></span>\")\n )\n\ncanvas = manifest.make_canvas(id=f\"{base_url}/canvas/segment1\", duration=1801.055)\nanno_body = ResourceItem(id=\"https://fixtures.iiif.io/video/indiana/30-minute-clock/medium/30-minute-clock.mp4\",\n type=\"Video\",\n format=\"video/mp4\",\n duration=1801.055)\nanno_page = AnnotationPage(id=f\"{base_url}/annotation/segment1/page\")\nanno = Annotation(id=f\"{base_url}/annotation/segment1-video\",\n motivation=\"painting\",\n body=anno_body,\n target=canvas.id)\n\nanno_page.add_item(anno)\ncanvas.add_item(anno_page)\n\nmanifest.start = SpecificResource(id=f\"{base_url}/canvas-start/segment1\",\n source=canvas.id,\n selector={\"type\": \"PointSelector\", \"t\": 120.5})\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0017-transcription-av/","title":"Providing Access to Transcript Files of A/V Content","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0017-transcription-av/ JSON-LD: https://iiif.io/api/cookbook/recipe/0017-transcription-av/manifest.json"},{"location":"recipes/0017-transcription-av/#method-1-building-the-rendering-structure-using-the-externalitem-class","title":"Method 1 - Building the rendering
structure using the ExternalItem
class","text":"from iiif_prezi3 import Manifest, ExternalItem, ResourceItem, AnnotationPage, Annotation, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0017-transcription-av\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\",\n label=\"Volleyball for Boys\")\n\ncanvas = manifest.make_canvas(id=f\"{base_url}/canvas\")\nanno_body = ResourceItem(id=\"https://fixtures.iiif.io/video/indiana/volleyball/high/volleyball-for-boys.mp4\",\n type=\"Video\",\n format=\"video/mp4\")\nanno_page = AnnotationPage(id=f\"{base_url}/canvas/page\")\nanno = Annotation(id=f\"{base_url}/canvas/page/annotation\",\n motivation=\"painting\",\n body=anno_body,\n target=canvas.id)\n\nhwd = {\"height\": 1080, \"width\": 1920, \"duration\": 662.037}\nanno_body.set_hwd(**hwd)\ncanvas.set_hwd(**hwd)\n\nanno_page.add_item(anno)\ncanvas.add_item(anno_page)\n\nrendering = ExternalItem(id=\"https://fixtures.iiif.io/video/indiana/volleyball/volleyball.txt\",\n type=\"Text\",\n label=\"Transcript\",\n format=\"text/plain\")\n\ncanvas.rendering = [rendering]\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0019-html-in-annotations/","title":"HTML in Annotations","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0019-html-in-annotations/ JSON-LD: https://iiif.io/api/cookbook/recipe/0019-html-in-annotations/manifest.json"},{"location":"recipes/0019-html-in-annotations/#method-1-construct-an-annotation-using-the-make_annotation-helper-and-a-dictionary-of-the-body-properties","title":"Method 1 - Construct an Annotation using the make_annotation
helper and a dictionary of the body
properties","text":"from iiif_prezi3 import Manifest\n\nbase_url = \"https://iiif.io/api/cookbook/recipe/0019-html-in-annotations\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\",\n label={\"en\": [\"Picture of G\u00f6ttingen taken during the 2019 IIIF Conference\"]})\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/918ecd18c2592080851777620de9bcb5-gottingen\",\n id=f\"{base_url}/canvas-1\",\n anno_id=f\"{base_url}/canvas-1/annopage-1/anno-1\",\n anno_page_id=f\"{base_url}/canvas-1/annopage-1\")\n\nanno = canvas.make_annotation(id=f\"{base_url}/canvas-1/annopage-2/anno-1\",\n motivation=\"commenting\",\n body={\"type\": \"TextualBody\",\n \"language\": \"de\",\n \"format\": \"text/html\",\n \"value\": \"<p>G\u00f6ttinger Marktplatz mit <a href='https://de.wikipedia.org/wiki/G%C3%A4nseliesel-Brunnen_(G%C3%B6ttingen)'>G\u00e4nseliesel Brunnen <img src='https://en.wikipedia.org/static/images/project-logos/enwiki.png' alt='Wikipedia logo'></a></p>\"},\n target=canvas.id,\n anno_page_id=f\"{base_url}/canvas-1/annopage-2\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0021-tagging/","title":"Simple Annotation \u2014 Tagging","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0021-tagging/ JSON-LD: https://iiif.io/api/cookbook/recipe/0021-tagging/manifest.json"},{"location":"recipes/0021-tagging/#method-1-construct-an-annotation-using-the-make_annotation-helper-and-a-dictionary-of-the-body-properties","title":"Method 1 - Construct an Annotation using the make_annotation
helper and a dictionary of the body
properties","text":"from iiif_prezi3 import Manifest\n\nbase_url = \"https://iiif.io/api/cookbook/recipe/0021-tagging\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\",\n label={\"en\": [\"Picture of G\u00f6ttingen taken during the 2019 IIIF Conference\"]})\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/918ecd18c2592080851777620de9bcb5-gottingen\",\n id=f\"{base_url}/canvas/p1\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\nanno = canvas.make_annotation(id=f\"{base_url}/annotation/p0002-tag\",\n motivation=\"tagging\",\n body={\"type\": \"TextualBody\",\n \"language\": \"de\",\n \"format\": \"text/plain\",\n \"value\": \"G\u00e4nseliesel-Brunnen\"},\n target=canvas.id + \"#xywh=265,661,1260,1239\",\n anno_page_id=f\"{base_url}/page/p2/1\")\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0036-composition-from-multiple-images/","title":"Composition from Multiple Images","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0036-composition-from-multiple-images/ JSON-LD: https://iiif.io/api/cookbook/recipe/0036-composition-from-multiple-images/manifest.json"},{"location":"recipes/0036-composition-from-multiple-images/#method-1-add-multiple-annotations-with-add_item-helper","title":"Method 1 - Add Multiple Annotations with add_item() helper","text":"from iiif_prezi3 import Manifest, ResourceItem, AnnotationPage, Annotation, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0036-composition-from-multiple-images\"\n\nmanifest = Manifest(\n id=f\"{base_url}/manifest.json\",\n label=\"Folio from Grandes Chroniques de France, ca. 1460\"\n)\ncanvas = manifest.make_canvas(\n id=f\"{base_url}/canvas/p1\",\n height=5412,\n width=7216\n)\ncanvas.add_label(language=\"none\", value=\"f. 033v-034r [Chilp\u00e9ric Ier tue Galswinthe, se remarie et est assassin\u00e9]\")\n\nanno_body_a = ResourceItem(\n id=\"https://iiif.io/api/image/3.0/example/reference/899da506920824588764bc12b10fc800-bnf_chateauroux/full/max/0/default.jpg\",\n type=\"Image\",\n format=\"image/jpeg\",\n height=5412,\n width=7216\n)\nanno_body_a.make_service(\n id=\"https://iiif.io/api/image/3.0/example/reference/899da506920824588764bc12b10fc800-bnf_chateauroux\",\n type=\"ImageService3\",\n profile=\"level1\"\n)\nanno_page = AnnotationPage(\n id=f\"{base_url}/page/p1/1\"\n)\nannotation_a = Annotation(\n id=f\"{base_url}/annotation/p0001-image\",\n motivation=\"painting\",\n body=anno_body_a,\n target=canvas.id\n)\n\nanno_body_b = ResourceItem(\n id=\"https://iiif.io/api/image/3.0/example/reference/899da506920824588764bc12b10fc800-bnf_chateauroux_miniature/full/max/0/default.jpg\",\n type=\"Image\",\n format=\"image/jpeg\",\n width=2138,\n height=2414\n)\nanno_body_b.add_label(language=\"fr\", value=\"Miniature [Chilp\u00e9ric Ier tue Galswinthe, se remarie et est assassin\u00e9]\")\nanno_body_b.make_service(\n id=\"https://iiif.io/api/image/3.0/example/reference/899da506920824588764bc12b10fc800-bnf_chateauroux_miniature\",\n type=\"ImageService3\",\n profile=\"level1\"\n)\nannotation_b = Annotation(\n id=f\"{base_url}/annotation/p0002-image\",\n motivation=\"painting\",\n body=anno_body_b,\n target=f\"{canvas.id}#xywh=3949,994,1091,1232\"\n)\n\nanno_page.add_item(annotation_a)\nanno_page.add_item(annotation_b)\ncanvas.add_item(anno_page)\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0047-homepage/","title":"Linking to Web Page of an Object","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0047-homepage/ JSON-LD: https://iiif.io/api/cookbook/recipe/0047-homepage/manifest.json"},{"location":"recipes/0047-homepage/#method-1-add-homepage-as-homepageitem","title":"Method 1 - Add Homepage as HomepageItem","text":"from iiif_prezi3 import Manifest, ResourceItem, AnnotationPage, Annotation, config, HomepageItem\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"none\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0047-homepage\"\n\nhomepage = HomepageItem(\n id=\"https://www.getty.edu/art/collection/object/103RQQ\",\n type=\"Text\",\n label={\"en\": [\"Home page at the Getty Museum Collection\"]},\n format=\"text/html\",\n language=\"en\",\n)\nmanifest = Manifest(\n id=f\"{base_url}/manifest.json\",\n label=\"Laoc\u00f6on\",\n homepage=homepage,\n)\ncanvas = manifest.make_canvas(\n id=f\"{base_url}/canvas/1\",\n label=\"Front\"\n)\nanno_body = ResourceItem(\n id=\"https://iiif.io/api/image/3.0/example/reference/28473c77da3deebe4375c3a50572d9d3-laocoon/full/!500,500/0/default.jpg\",\n type=\"Image\",\n format=\"image/jpeg\"\n)\nanno_body.make_service(\n id=\"https://iiif.io/api/image/3.0/example/reference/28473c77da3deebe4375c3a50572d9d3-laocoon\",\n type=\"ImageService3\",\n profile=\"level1\"\n)\nanno_page = AnnotationPage(\n id=f\"{base_url}/canvas/1/page/1\"\n)\nhw = {\"height\": 3000, \"width\": 2315}\nanno_body.set_hwd(**hw)\ncanvas.set_hwd(**hw)\nanno = Annotation(\n id=f\"{base_url}/canvas/1/page/1/annotation/1\",\n motivation=\"painting\",\n body=anno_body,\n target=canvas.id\n)\nanno_page.add_item(anno)\ncanvas.add_item(anno_page)\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0074-multiple-language-captions/","title":"Using Caption and Subtitle Files in Multiple Languages with Video Content","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0074-multiple-language-captions/ JSON-LD: https://iiif.io/api/cookbook/recipe/0074-multiple-language-captions/manifest.json"},{"location":"recipes/0074-multiple-language-captions/#method-1-construct-supplementing-annotation-using-the-make_annotation-helper-and-a-dictionary-of-the-body-properties","title":"Method 1 - Construct Supplementing Annotation Using the make_annotation
helper and a dictionary of the body
properties","text":"from iiif_prezi3 import Manifest, ResourceItem, AnnotationPage, Annotation, KeyValueString, config, Choice\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0074-multiple-language-captions\"\n\nmanifest = Manifest(\n id=f\"{base_url}/manifest.json\",\n label=\"For ladies. French models\",\n rights=\"http://rightsstatements.org/vocab/InC/1.0/\",\n requiredStatement=KeyValueString(label=\"Rights\", value=\"All rights reserved Cinecitt\u00e0 Luce spa\")\n)\nmanifest.add_label(language=\"it\", value=\"Per voi signore. Modelli francesi\")\n\ncanvas = manifest.make_canvas(\n id=f\"{base_url}/canvas\"\n)\nvideo_resource = ResourceItem(\n id=\"https://fixtures.iiif.io/video/europeana/Per_voi_signore_Modelli_francesi.mp4\",\n type=\"Video\",\n format=\"video/mp4\"\n)\nvideo_hwd = {\"height\": 384, \"width\": 288, \"duration\": 65.0}\nvideo_resource.set_hwd(**video_hwd)\ncanvas.set_hwd(**video_hwd)\npainting_annotation = Annotation(\n id=f\"{base_url}/canvas/page/annotation\",\n motivation=\"painting\",\n body=video_resource,\n target=canvas.id\n)\nannotation_page = AnnotationPage(\n id=f\"{base_url}/canvas/page\"\n)\nannotation_page.add_item(painting_annotation)\ncanvas.add_item(annotation_page)\n\nitalian_captions = ResourceItem(\n id=f\"{base_url}/Per_voi_signore_Modelli_francesi_it.vtt\",\n type=\"Text\",\n format=\"text/vtt\",\n language=\"it\",\n)\nitalian_captions.add_label(language=\"it\", value=\"Sottotitoli in formato WebVTT\")\nenglish_captions = ResourceItem(\n id=f\"{base_url}/Per_voi_signore_Modelli_francesi_en.vtt\",\n type=\"Text\",\n format=\"text/vtt\",\n language=\"en\"\n)\nenglish_captions.add_label(language=\"en\", value=\"Captions in WebVTT format\")\nchoice = Choice(\n items=[english_captions, italian_captions]\n)\n\ncaption_annotation = canvas.make_annotation(\n id=f\"{base_url}/manifest.json/subtitles_captions-files-vtt\",\n motivation=\"supplementing\",\n body=choice,\n target=canvas.id,\n anno_page_id=f\"{base_url}/manifest.json/anno/page/1\"\n)\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0118-multivalue/","title":"Displaying Multiple Values with Language Maps","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0118_multivalue/ JSON-LD: https://iiif.io/api/cookbook/recipe/0118_multivalue/manifest.json"},{"location":"recipes/0118-multivalue/#method-1-use-a-keyvaluestring-object-and-a-dictionary-to-create-language-maps","title":"Method 1 - Use a KeyValueString
object and a dictionary to create language maps.","text":"from iiif_prezi3 import Manifest, KeyValueString\n\nbase_url = \"https://iiif.io/api/cookbook/recipe/0118-multivalue\"\n\nmanifest = Manifest(id=\"https://iiif.io/api/cookbook/recipe/0118_multivalue/manifest.json\",\n label={\"fr\": [\"Arrangement en gris et noir no 1\"]})\nmanifest.metadata = [\n KeyValueString(label={\"en\": [\"Alternative titles\"]},\n value={\"en\": [\"Whistler's Mother\", \"Arrangement in Grey and Black No. 1\"],\n \"fr\": [\"Portrait de la m\u00e8re de l'artiste\", \"La M\u00e8re de Whistler\"]})\n]\nmanifest.summary = {\"en\": [\"A painting in oil on canvas created by the American-born painter James McNeill Whistler, in 1871.\"]}\n\ncanvas = manifest.make_canvas(id=\"https://iiif.io/api/cookbook/recipe/0118_multivalue/canvas/1\", height=991, width=1114)\nanno_page = canvas.add_image(image_url=\"https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Whistlers_Mother_high_res.jpg/1114px-Whistlers_Mother_high_res.jpg\",\n anno_page_id=\"https://iiif.io/api/cookbook/recipe/0118_multivalue/canvas/1/page/1\",\n anno_id=\"https://iiif.io/api/cookbook/recipe/0118_multivalue/canvas/1/page/1/annotation/1\",\n format=\"image/jpeg\",\n )\n\ncanvas.items[0].items[0].id = \"https://iiif.io/api/cookbook/recipe/0118_multivalue/canvas/1/page/1/annotation/1\"\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0230-navdate/","title":"Navigation by Chronology","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0230-navdate/ JSON-LD Example 1 - 1986 Map: https://iiif.io/api/cookbook/recipe/0230-navdate/navdate_map_2-manifest.json JSON-LD Example 2 - 1987 Map: https://iiif.io/api/cookbook/recipe/0230-navdate/navdate_map_1-manifest.json JSON-LD Example 3 - Collection: https://iiif.io/api/cookbook/recipe/0230-navdate/navdate-collection.json"},{"location":"recipes/0230-navdate/#method-1-setting-the-navdate-property-during-object-construction-using-a-datetime-object","title":"Method 1 - Setting the navDate
property during object construction using a datetime
object","text":""},{"location":"recipes/0230-navdate/#example-1-1986-map","title":"Example 1 - 1986 Map","text":"from iiif_prezi3 import Manifest, config\nfrom datetime import datetime, timezone\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0230-navdate\"\n\n# n.b: You MUST set `tzinfo` as the Prezi3 Specification requires a timezone, and the default `datetime` does not have one.\nmanifest = Manifest(id=f\"{base_url}/navdate_map_2-manifest.json\",\n label=\"1986 Chesapeake and Ohio Canal, Washington, D.C., Maryland, West Virginia, official map and guide\",\n navDate=datetime(1986, 1, 1, tzinfo=timezone.utc))\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-87691274-1986\",\n id=f\"{base_url}/canvas/p1\",\n label=\"1986 Map, recto and verso, with a date of publication\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\n# This is a workaround for an inconsistency in the Cookbook JSON - see https://github.com/IIIF/cookbook-recipes/issues/376\ncanvas.items[0].items[0].body.service[0].id = \"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-87691274-1986/\"\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0230-navdate/#example-2-1987-map","title":"Example 2 - 1987 Map","text":"from iiif_prezi3 import Manifest, config\nfrom datetime import datetime, timezone\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0230-navdate\"\n\n# n.b: You MUST set `tzinfo` as the Prezi3 Specification requires a timezone, and the default `datetime` does not have one.\nmanifest = Manifest(id=f\"{base_url}/navdate_map_1-manifest.json\",\n label=\"1987 Chesapeake and Ohio Canal, Washington, D.C., Maryland, West Virginia, official map and guide\",\n navDate=datetime(1987, 1, 1, tzinfo=timezone.utc))\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-88695674\",\n id=f\"{base_url}/canvas/p1\",\n label=\"1987 Map, recto and verso, with a date of publication\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\n# This is a workaround for an inconsistency in the Cookbook JSON - see https://github.com/IIIF/cookbook-recipes/issues/376\ncanvas.items[0].items[0].body.service[0].id = \"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-88695674/\"\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0230-navdate/#example-3-collection","title":"Example 3 - Collection","text":"Here we can make use of the fact that iiif-prezi3
will automatically turn a Manifest into a reference when it is added to a Collection object.
from iiif_prezi3 import Collection, Manifest, ResourceItem, config\nfrom datetime import datetime, timezone\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0230-navdate\"\n\n# n.b: You MUST set `tzinfo` as the Prezi3 Specification requires a timezone, and the default `datetime` does not have one.\nmanifest1986 = Manifest(id=f\"{base_url}/navdate_map_2-manifest.json\",\n label=\"1986 Chesapeake and Ohio Canal, Washington, D.C., Maryland, West Virginia, official map and guide\",\n navDate=datetime(1986, 1, 1, tzinfo=timezone.utc))\ncanvas1986 = manifest1986.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-87691274-1986\",\n id=f\"{base_url}/canvas/p1\",\n label=\"1986 Map, recto and verso, with a date of publication\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\nmanifest1987 = Manifest(id=f\"{base_url}/navdate_map_1-manifest.json\",\n label=\"1987 Chesapeake and Ohio Canal, Washington, D.C., Maryland, West Virginia, official map and guide\",\n navDate=datetime(1987, 1, 1, tzinfo=timezone.utc))\ncanvas1987 = manifest1987.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-88695674\",\n id=f\"{base_url}/canvas/p1\",\n label=\"1987 Map, recto and verso, with a date of publication\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\ncollection = Collection(id=f\"{base_url}/navdate-collection.json\",\n label=\"Chesapeake and Ohio Canal map and guide pamphlets\")\nthumbnail = ResourceItem(id=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-88695674/full/max/0/default.jpg\",\n type=\"Image\",\n format=\"image/jpeg\",\n height=300,\n width=221)\nthumbnail.make_service(id=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-88695674\",\n type=\"ImageService3\",\n profile=\"level1\")\ncollection.thumbnail = [thumbnail]\n\ncollection.add_item(manifest1986)\ncollection.add_item(manifest1987)\ncollection.items[0].navDate = manifest1986.navDate\ncollection.items[1].navDate = manifest1987.navDate\n\nprint(collection.json(indent=2))\n
"},{"location":"recipes/0230-navdate/#method-2-setting-the-navdate-property-with-a-string","title":"Method 2 - Setting the navDate
property with a string","text":""},{"location":"recipes/0230-navdate/#example-1-1986-map_1","title":"Example 1 - 1986 Map","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0230-navdate\"\n\nmanifest = Manifest(id=f\"{base_url}/navdate_map_2-manifest.json\",\n label=\"1986 Chesapeake and Ohio Canal, Washington, D.C., Maryland, West Virginia, official map and guide\",\n navDate=\"1986-01-01T00:00:00Z\")\n\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-87691274-1986\",\n id=f\"{base_url}/canvas/p1\",\n label=\"1986 Map, recto and verso, with a date of publication\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\n# This is a workaround for an inconsistency in the Cookbook JSON - see https://github.com/IIIF/cookbook-recipes/issues/376\ncanvas.items[0].items[0].body.service[0].id = \"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-87691274-1986/\"\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0230-navdate/#example-2-1987-map_1","title":"Example 2 - 1987 Map","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0230-navdate\"\n\nmanifest = Manifest(id=f\"{base_url}/navdate_map_1-manifest.json\",\n label=\"1987 Chesapeake and Ohio Canal, Washington, D.C., Maryland, West Virginia, official map and guide\",\n navDate=\"1987-01-01T00:00:00Z\")\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-88695674\",\n id=f\"{base_url}/canvas/p1\",\n label=\"1987 Map, recto and verso, with a date of publication\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\n\n# This is a workaround for an inconsistency in the Cookbook JSON - see https://github.com/IIIF/cookbook-recipes/issues/376\ncanvas.items[0].items[0].body.service[0].id = \"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-88695674/\"\n\nprint(manifest.json(indent=2))\n
"},{"location":"recipes/0230-navdate/#example-3-collection_1","title":"Example 3 - Collection","text":"To show the different possible approaches, here we will build the Collection object manually using the ManifestRef
class.
from iiif_prezi3 import Collection, ManifestRef, ResourceItem, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0230-navdate\"\n\ncollection = Collection(id=f\"{base_url}/navdate-collection.json\",\n label=\"Chesapeake and Ohio Canal map and guide pamphlets\")\nthumbnail = ResourceItem(id=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-88695674/full/max/0/default.jpg\",\n type=\"Image\",\n format=\"image/jpeg\",\n height=300,\n width=221)\nthumbnail.make_service(id=\"https://iiif.io/api/image/3.0/example/reference/43153e2ec7531f14dd1c9b2fc401678a-88695674\",\n type=\"ImageService3\",\n profile=\"level1\")\ncollection.thumbnail = [thumbnail]\n\nmanifest1986 = ManifestRef(id=f\"{base_url}/navdate_map_2-manifest.json\",\n type=\"Manifest\",\n label=\"1986 Chesapeake and Ohio Canal, Washington, D.C., Maryland, West Virginia, official map and guide\",\n navDate=\"1986-01-01T00:00:00+00:00\")\n\nmanifest1987 = ManifestRef(id=f\"{base_url}/navdate_map_1-manifest.json\",\n type=\"Manifest\",\n label=\"1987 Chesapeake and Ohio Canal, Washington, D.C., Maryland, West Virginia, official map and guide\",\n navDate=\"1987-01-01T00:00:00+00:00\")\n\ncollection.add_item(manifest1986)\ncollection.add_item(manifest1987)\n\nprint(collection.json(indent=2))\n
"},{"location":"recipes/0261-non-rectangular-commenting/","title":"Annotation with a Non-Rectangular Polygon","text":"Cookbook URLs Recipe: https://iiif.io/api/cookbook/recipe/0261-non-rectangular-commenting/ JSON-LD: https://iiif.io/api/cookbook/recipe/0261-non-rectangular-commenting/manifest.json"},{"location":"recipes/0261-non-rectangular-commenting/#method-1-","title":"Method 1 -","text":"from iiif_prezi3 import Manifest, config\n\nconfig.configs['helpers.auto_fields.AutoLang'].auto_lang = \"en\"\nbase_url = \"https://iiif.io/api/cookbook/recipe/0261-non-rectangular-commenting\"\n\nmanifest = Manifest(id=f\"{base_url}/manifest.json\", label=\"Picture of G\u00f6ttingen taken during the 2019 IIIF Conference\")\ncanvas = manifest.make_canvas_from_iiif(url=\"https://iiif.io/api/image/3.0/example/reference/918ecd18c2592080851777620de9bcb5-gottingen\",\n id=f\"{base_url}/canvas/p1\",\n anno_id=f\"{base_url}/annotation/p0001-image\",\n anno_page_id=f\"{base_url}/page/p1/1\")\nanno = canvas.make_annotation(id=f\"{base_url}/annotation/p0002-svg\",\n motivation=\"tagging\",\n body={\"type\": \"TextualBody\",\n \"language\": \"de\",\n \"format\": \"text/plain\",\n \"value\": \"G\u00e4nseliesel-Brunnen\"},\n target={\"type\": \"SpecificResource\",\n \"source\": canvas.id,\n \"selector\": {\"type\": \"SvgSelector\",\n \"value\": \"<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'><g><path d='M270.000000,1900.000000 L1530.000000,1900.000000 L1530.000000,1610.000000 L1315.000000,1300.000000 L1200.000000,986.000000 L904.000000,661.000000 L600.000000,986.000000 L500.000000,1300.000000 L270,1630 L270.000000,1900.000000' /></g></svg>\"\n }\n },\n anno_page_id=f\"{base_url}/page/p2/1\")\n\nprint(manifest.json(indent=2))\n
"}]}
\ No newline at end of file
diff --git a/write-helper-method/index.html b/write-helper-method/index.html
index f6b773c..e8db676 100644
--- a/write-helper-method/index.html
+++ b/write-helper-method/index.html
@@ -850,6 +850,27 @@
+
+
+
+
+
+ Composition from Multiple Images
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+