Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookbook recipe examples #127

Merged
merged 1 commit into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/recipes/0001-mvm-image.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Simplest Manifest - Single Image File
### Recipe: [https://iiif.io/api/cookbook/recipe/0001-mvm-image/](https://iiif.io/api/cookbook/recipe/0001-mvm-image/)
### JSON-LD: [https://iiif.io/api/cookbook/recipe/0001-mvm-image/manifest.json](https://iiif.io/api/cookbook/recipe/0001-mvm-image/manifest.json)

## Method 1 - Using the `make_canvas` and `add_image` helpers
```python
from iiif_prezi3 import Manifest, config

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"

manifest = Manifest(id="https://iiif.io/api/cookbook/recipe/0001-mvm-image/manifest.json", label="Image 1")
canvas = manifest.make_canvas(id="https://iiif.io/api/cookbook/recipe/0001-mvm-image/canvas/p1", height=1800, width=1200)
anno_page = canvas.add_image(image_url="http://iiif.io/api/presentation/2.1/example/fixtures/resources/page1-full.png",
anno_page_id="https://iiif.io/api/cookbook/recipe/0001-mvm-image/page/p1/1",
anno_id="https://iiif.io/api/cookbook/recipe/0001-mvm-image/annotation/p0001-image",
format="image/png",
height=1800,
width=1200
)

print(manifest.json(indent=2))
```

## Method 2 - Building the structure manually and using the `add_item` helper
```python
from iiif_prezi3 import Manifest, Canvas, AnnotationPage, Annotation, ResourceItem, config

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"

manifest = Manifest(id="https://iiif.io/api/cookbook/recipe/0001-mvm-image/manifest.json", label="Image 1")
canvas = Canvas(id="https://iiif.io/api/cookbook/recipe/0001-mvm-image/canvas/p1", height=1800, width=1200)
anno_body = ResourceItem(id="http://iiif.io/api/presentation/2.1/example/fixtures/resources/page1-full.png",
type="Image",
format="image/png",
height=1800,
width=1200)
anno_page = AnnotationPage(id="https://iiif.io/api/cookbook/recipe/0001-mvm-image/page/p1/1")
anno = Annotation(id="https://iiif.io/api/cookbook/recipe/0001-mvm-image/annotation/p0001-image",
motivation="painting",
body=anno_body,
target=canvas.id)
anno_page.add_item(anno)
canvas.add_item(anno_page)
manifest.add_item(canvas)

print(manifest.json(indent=2))
```

26 changes: 26 additions & 0 deletions docs/recipes/0002-mvm-audio.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Simplest Manifest - Audio
### Recipe: [https://iiif.io/api/cookbook/recipe/0002-mvm-audio/](https://iiif.io/api/cookbook/recipe/0002-mvm-audio/)
### JSON-LD: [https://iiif.io/api/cookbook/recipe/0002-mvm-audio/manifest.json](https://iiif.io/api/cookbook/recipe/0002-mvm-audio/manifest.json)

## Method 1 - Building the structure and using the `add_item` helper
```python
from iiif_prezi3 import Manifest, AnnotationPage, Annotation, ResourceItem, config

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"

manifest = Manifest(id="https://iiif.io/api/cookbook/recipe/0002-mvm-audio/manifest.json", label="Simplest Audio Example")
canvas = manifest.make_canvas(id="https://iiif.io/api/cookbook/recipe/0002-mvm-audio/canvas", duration=1985.024)
anno_body = ResourceItem(id="https://fixtures.iiif.io/audio/indiana/mahler-symphony-3/CD1/medium/128Kbps.mp4",
type="Sound",
format="audio/mp4",
duration=1985.024)
anno_page = AnnotationPage(id="https://iiif.io/api/cookbook/recipe/0002-mvm-audio/canvas/page")
anno = Annotation(id="https://iiif.io/api/cookbook/recipe/0002-mvm-audio/canvas/page/annotation",
motivation="painting",
body=anno_body,
target=canvas.id)
anno_page.add_item(anno)
canvas.add_item(anno_page)

print(manifest.json(indent=2))
```
30 changes: 30 additions & 0 deletions docs/recipes/0003-mvm-video.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Simplest Manifest - Video
### Recipe: [https://iiif.io/api/cookbook/recipe/0003-mvm-video/](https://iiif.io/api/cookbook/recipe/0003-mvm-video/)
### JSON-LD: [https://iiif.io/api/cookbook/recipe/0003-mvm-video/manifest.json](https://iiif.io/api/cookbook/recipe/0003-mvm-video/manifest.json)

## Method 1 - Building the structure manually and using the `add_item` helper
```python
from iiif_prezi3 import Manifest, AnnotationPage, Annotation, ResourceItem, config

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"

manifest = Manifest(id="https://iiif.io/api/cookbook/recipe/0003-mvm-video/manifest.json", label="Video Example 3")
canvas = manifest.make_canvas(id="https://iiif.io/api/cookbook/recipe/0003-mvm-video/canvas")
anno_body = ResourceItem(id="https://fixtures.iiif.io/video/indiana/lunchroom_manners/high/lunchroom_manners_1024kb.mp4",
type="Video",
format="video/mp4")
anno_page = AnnotationPage(id="https://iiif.io/api/cookbook/recipe/0003-mvm-video/canvas/page")
anno = Annotation(id="https://iiif.io/api/cookbook/recipe/0003-mvm-video/canvas/page/annotation",
motivation="painting",
body=anno_body,
target=canvas.id)

hwd = {"height": 360, "width": 480, "duration": 572.034}
anno_body.set_hwd(**hwd)
canvas.set_hwd(**hwd)

anno_page.add_item(anno)
canvas.add_item(anno_page)

print(manifest.json(indent=2))
```
29 changes: 29 additions & 0 deletions docs/recipes/0004-canvas-size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Image and Canvas with Differing Dimensions
### Recipe: [https://iiif.io/api/cookbook/recipe/0004-canvas-size/](https://iiif.io/api/cookbook/recipe/0004-canvas-size/)
### JSON-LD: [https://iiif.io/api/cookbook/recipe/0004-canvas-size/manifest.json](https://iiif.io/api/cookbook/recipe/0004-canvas-size/manifest.json)

## Method 1 - Using the `set_hwd` helper
```python
from iiif_prezi3 import Manifest, AnnotationPage, Annotation, ResourceItem, config

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"

manifest = Manifest(id="https://iiif.io/api/cookbook/recipe/0004-canvas-size/manifest.json", label="Still image from an opera performance at Indiana University")
canvas = manifest.make_canvas(id="https://iiif.io/api/cookbook/recipe/0004-canvas-size/canvas/p1")
anno_body = ResourceItem(id="https://fixtures.iiif.io/video/indiana/donizetti-elixir/act1-thumbnail.png",
type="Image",
format="image/png")
anno_page = AnnotationPage(id="https://iiif.io/api/cookbook/recipe/0004-canvas-size/canvas/page/p1/1")
anno = Annotation(id="https://iiif.io/api/cookbook/recipe/0004-canvas-size/annotation/p0001-image",
motivation="painting",
body=anno_body,
target=canvas.id)

anno_body.set_hwd(height=360, width=640)
canvas.set_hwd(height=1080, width=1920)

anno_page.add_item(anno)
canvas.add_item(anno_page)

print(manifest.json(indent=2))
```
20 changes: 20 additions & 0 deletions docs/recipes/0005-image-service.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Support Deep Viewing with Basic Use of a IIIF Image Service
### Recipe: [https://iiif.io/api/cookbook/recipe/0005-image-service/](https://iiif.io/api/cookbook/recipe/0005-image-service/)
### JSON-LD: [https://iiif.io/api/cookbook/recipe/0005-image-service/manifest.json](https://iiif.io/api/cookbook/recipe/0005-image-service/manifest.json)

## Method 1 - Using the `make_canvas_from_iiif` helper
```python
from iiif_prezi3 import Manifest, config

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"

manifest = Manifest(id="https://iiif.io/api/cookbook/recipe/0005-image-service/manifest.json", label="Picture of Göttingen taken during the 2019 IIIF Conference")
canvas = manifest.make_canvas_from_iiif(url="https://iiif.io/api/image/3.0/example/reference/918ecd18c2592080851777620de9bcb5-gottingen",
id="https://iiif.io/api/cookbook/recipe/0005-image-service/canvas/p1",
label="Canvas with a single IIIF image")
canvas.items[0].id = "https://iiif.io/api/cookbook/recipe/0005-image-service/page/p1/1"
canvas.items[0].items[0].id = "https://iiif.io/api/cookbook/recipe/0005-image-service/annotation/p0001-image"

print(manifest.json(indent=2))
```

27 changes: 27 additions & 0 deletions docs/recipes/0006-text-language.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Internationalization and Multi-language Values
### Recipe: [https://iiif.io/api/cookbook/recipe/0006-text-language/](https://iiif.io/api/cookbook/recipe/0006-text-language/)
### JSON-LD: [https://iiif.io/api/cookbook/recipe/0006-text-language/manifest.json](https://iiif.io/api/cookbook/recipe/0006-text-language/manifest.json)

## Method 1 - Construct the language dictionaries during object creation
```python
from iiif_prezi3 import Manifest, KeyValueString

manifest = Manifest(id="https://iiif.io/api/cookbook/recipe/0006-text-language/manifest.json",
label={"en": ["Whistler's Mother"], "fr": ["La Mère de Whistler"]})
manifest.metadata = [
KeyValueString(label={"en": ["Creator"], "fr": ["Auteur"]}, value="Whistler, James Abbott McNeill"),
KeyValueString(label={"en": ["Subject"], "fr": ["Sujet"]},
value={"en": ["McNeill Anna Matilda, mother of Whistler (1804-1881)"],
"fr": ["McNeill Anna Matilda, mère de Whistler (1804-1881)"]})
]
manifest.summary = {"en": ["Arrangement in Grey and Black No. 1, also called Portrait of the Artist's Mother."],
"fr": ["Arrangement en gris et noir n°1, also called Portrait de la mère de l'artiste."]}
manifest.requiredStatement = KeyValueString(label={"en": ["Held By"], "fr": ["Détenu par"]}, value="Musée d'Orsay, Paris, France")

canvas = manifest.make_canvas_from_iiif(url="https://iiif.io/api/image/3.0/example/reference/329817fc8a251a01c393f517d8a17d87-Whistlers_Mother",
id="https://iiif.io/api/cookbook/recipe/0006-text-language/canvas/p1")
canvas.items[0].id = "https://iiif.io/api/cookbook/recipe/0006-text-language/page/p1/1"
canvas.items[0].items[0].id = "https://iiif.io/api/cookbook/recipe/0006-text-language/annotation/p0001-image"

print(manifest.json(indent=2))
```
24 changes: 24 additions & 0 deletions docs/recipes/0007-string-formats.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Embedding HTML in descriptive properties
### Recipe: [https://iiif.io/api/cookbook/recipe/0007-string-formats/](https://iiif.io/api/cookbook/recipe/0007-string-formats/)
### JSON-LD: [https://iiif.io/api/cookbook/recipe/0007-string-formats/manifest.json](https://iiif.io/api/cookbook/recipe/0007-string-formats/manifest.json)

## Method 1 - Building the object directly and making use of the AutoLang config
```python
from iiif_prezi3 import Manifest, KeyValueString, config

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"

manifest = Manifest(id="https://iiif.io/api/cookbook/recipe/0007-string-formats/manifest.json",
label="Picture of Göttingen taken during the 2019 IIIF Conference",
summary="<p>Picture taken by the <a href=\"https://github.com/glenrobson\">IIIF Technical Coordinator</a></p>",
rights="http://creativecommons.org/licenses/by-sa/3.0/",
requiredStatement=KeyValueString(label="Attribution",
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>"),
metadata=[KeyValueString(label="Author", value={"none": ["<span><a href='https://github.com/glenrobson'>Glen Robson</a></span>"]})])
canvas = manifest.make_canvas_from_iiif(url="https://iiif.io/api/image/3.0/example/reference/918ecd18c2592080851777620de9bcb5-gottingen",
id="https://iiif.io/api/cookbook/recipe/0007-string-formats/canvas/p1")
canvas.items[0].id = "https://iiif.io/api/cookbook/recipe/0007-string-formats/page/p1/1"
canvas.items[0].items[0].id = "https://iiif.io/api/cookbook/recipe/0007-string-formats/annotation/p0001-image"

print(manifest.json(indent=2))
```
24 changes: 24 additions & 0 deletions docs/recipes/0008-rights.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Rights statement
### Recipe: [https://iiif.io/api/cookbook/recipe/0008-rights/](https://iiif.io/api/cookbook/recipe/0008-rights/)
### JSON-LD: [https://iiif.io/api/cookbook/recipe/0008-rights/manifest.json](https://iiif.io/api/cookbook/recipe/0008-rights/manifest.json)

## Method 1 - Building the object directly and making use of the AutoLang config
```python
from iiif_prezi3 import Manifest, KeyValueString, config

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"

manifest = Manifest(id="https://iiif.io/api/cookbook/recipe/0008-rights/manifest.json",
label="Picture of Göttingen taken during the 2019 IIIF Conference",
summary="<p>Picture taken by the <a href=\"https://github.com/glenrobson\">IIIF Technical Coordinator</a></p>",
rights="http://creativecommons.org/licenses/by-sa/3.0/",
requiredStatement=KeyValueString(label="Attribution",
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>"),
metadata=[KeyValueString(label="Author", value={"none": ["<span><a href='https://github.com/glenrobson'>Glen Robson</a></span>"]})])
canvas = manifest.make_canvas_from_iiif(url="https://iiif.io/api/image/3.0/example/reference/918ecd18c2592080851777620de9bcb5-gottingen",
id="https://iiif.io/api/cookbook/recipe/0008-rights/canvas/p1")
canvas.items[0].id = "https://iiif.io/api/cookbook/recipe/0008-rights/page/p1/1"
canvas.items[0].items[0].id = "https://iiif.io/api/cookbook/recipe/0008-rights/annotation/p0001-image"

print(manifest.json(indent=2))
```
45 changes: 45 additions & 0 deletions docs/recipes/0009-book-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Simple Manifest - Book
### Recipe: [https://iiif.io/api/cookbook/recipe/0009-book-1/](https://iiif.io/api/cookbook/recipe/0009-book-1/)
### JSON-LD: [https://iiif.io/api/cookbook/recipe/0009-book-1/manifest.json](https://iiif.io/api/cookbook/recipe/0009-book-1/manifest.json)

## Method 1 - Setting the `behavior` property during object construction
```python
from iiif_prezi3 import Manifest, config

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"

manifest = Manifest(id="https://iiif.io/api/cookbook/recipe/0009-book-1/manifest.json",
label="Simple Manifest - Book",
behavior=["paged"])
canvas1 = manifest.make_canvas_from_iiif(url="https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f18",
id="https://iiif.io/api/cookbook/recipe/0009-book-1/canvas/p1",
label="Blank page")
canvas1.items[0].id = "https://iiif.io/api/cookbook/recipe/0009-book-1/page/p1/1"
canvas1.items[0].items[0].id = "https://iiif.io/api/cookbook/recipe/0009-book-1/annotation/p0001-image"

canvas2 = manifest.make_canvas_from_iiif(url="https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f19",
id="https://iiif.io/api/cookbook/recipe/0009-book-1/canvas/p2",
label="Frontispiece")
canvas2.items[0].id = "https://iiif.io/api/cookbook/recipe/0009-book-1/page/p2/1"
canvas2.items[0].items[0].id = "https://iiif.io/api/cookbook/recipe/0009-book-1/annotation/p0002-image"

canvas3 = manifest.make_canvas_from_iiif(url="https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f20",
id="https://iiif.io/api/cookbook/recipe/0009-book-1/canvas/p3",
label="Title page")
canvas3.items[0].id = "https://iiif.io/api/cookbook/recipe/0009-book-1/page/p3/1"
canvas3.items[0].items[0].id = "https://iiif.io/api/cookbook/recipe/0009-book-1/annotation/p0003-image"

canvas4 = manifest.make_canvas_from_iiif(url="https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f21",
id="https://iiif.io/api/cookbook/recipe/0009-book-1/canvas/p4",
label="Blank page")
canvas4.items[0].id = "https://iiif.io/api/cookbook/recipe/0009-book-1/page/p4/1"
canvas4.items[0].items[0].id = "https://iiif.io/api/cookbook/recipe/0009-book-1/annotation/p0004-image"

canvas5 = manifest.make_canvas_from_iiif(url="https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f22",
id="https://iiif.io/api/cookbook/recipe/0009-book-1/canvas/p5",
label="Bookplate")
canvas5.items[0].id = "https://iiif.io/api/cookbook/recipe/0009-book-1/page/p5/1"
canvas5.items[0].items[0].id = "https://iiif.io/api/cookbook/recipe/0009-book-1/annotation/p0005-image"

print(manifest.json(indent=2))
```
Loading