File size: 26,032 Bytes
ac831e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
# IIIF APIs Reference (Image API 3.0 & Presentation API 3.0)

## Overview

The IIIF (International Image Interoperability Framework) consists of complementary APIs for delivering and presenting digital content:

- **Image API**: Web service for image manipulation and delivery via URI parameters
- **Presentation API**: JSON-LD format for describing structure, metadata, and presentation of compound digital objects
- **Content Search API**: Full-text search within IIIF resources

## IIIF Image API 3.0

## URI Syntax

### Base URI Template
```
{scheme}://{server}{/prefix}/{identifier}
```

### Image Request URI Template
```
{scheme}://{server}{/prefix}/{identifier}/{region}/{size}/{rotation}/{quality}.{format}
```

### Image Information Request URI Template
```
{scheme}://{server}{/prefix}/{identifier}/info.json
```

## URI Components

| Component | Description |
|-----------|-------------|
| scheme | HTTP or HTTPS protocol |
| server | Host server (may include port number) |
| prefix | Optional path to the service on the host server |
| identifier | Identifier of the requested image (ARK, URN, filename, etc.) |

**Important**: Special characters in identifiers MUST be URI encoded, including slashes (/).

## Image Request Parameters

Parameters must be specified in this exact order: region/size/rotation/quality.format

### Region Parameter

Defines the rectangular portion of the image to return.

| Form | Description | Example |
|------|-------------|---------|
| `full` | Return the complete image | `full` |
| `square` | Return square region (shorter dimension) | `square` |
| `x,y,w,h` | Pixel coordinates (x,y) and dimensions (w,h) | `125,15,120,140` |
| `pct:x,y,w,h` | Percentage coordinates and dimensions | `pct:41.6,7.5,40,70` |

### Size Parameter

Specifies dimensions for scaling the extracted region.

| Form | Description | Example |
|------|-------------|---------|
| `max` | Maximum size available (no upscaling) | `max` |
| `^max` | Maximum size (allows upscaling) | `^max` |
| `w,` | Scale to exact width | `150,` |
| `^w,` | Scale to exact width (allows upscaling) | `^200,` |
| `,h` | Scale to exact height | `,100` |
| `^,h` | Scale to exact height (allows upscaling) | `^,150` |
| `pct:n` | Scale to n percent (max 100%) | `pct:50` |
| `^pct:n` | Scale to n percent (allows upscaling) | `^pct:150` |
| `w,h` | Exact width and height (may distort) | `200,300` |
| `^w,h` | Exact width and height (allows upscaling) | `^250,400` |
| `!w,h` | Best fit within w,h (maintains aspect ratio) | `!200,300` |

### Rotation Parameter

Specifies mirroring and rotation to be applied to the image.

| Form | Description |
|------|-------------|
| `0` | No rotation |
| `90`, `180`, `270` | Clockwise rotation in degrees |
| `!0`, `!90`, etc. | Horizontal mirroring then rotation |

### Quality Parameter

Determines color characteristics of the image.

| Value | Description |
|-------|-------------|
| `default` | Server-determined default quality |
| `color` | Full color image |
| `gray` | Grayscale image |
| `bitonal` | Black and white image |

### Format Parameter

Specifies the output format.

Common formats: `jpg`, `png`, `gif`, `webp`, `tif`

---

## IIIF Presentation API 3.0

### Purpose
The Presentation API provides a standardized way to describe compound digital objects (books, manuscripts, albums, etc.) with their structure, metadata, and presentation instructions. It uses JSON-LD format to enable rich viewing experiences across different client applications.

### Core Resource Types

#### Collection
Ordered list of Manifests and/or other Collections for hierarchical organization.
```json
{
  "@context": "http://iiif.io/api/presentation/3/context.json",
  "id": "https://example.org/collection/books",
  "type": "Collection",
  "label": { "en": ["Book Collection"] },
  "items": [
    {
      "id": "https://example.org/manifest/book1",
      "type": "Manifest",
      "label": { "en": ["Book 1"] }
    }
  ]
}
```

#### Manifest
Describes a single compound object with its structure, metadata, and viewing instructions.
```json
{
  "@context": "http://iiif.io/api/presentation/3/context.json",
  "id": "https://example.org/manifest/book1",
  "type": "Manifest",
  "label": { "en": ["Example Book"] },
  "summary": { "en": ["A description of this book"] },
  "metadata": [
    {
      "label": { "en": ["Author"] },
      "value": { "en": ["Jane Doe"] }
    }
  ],
  "items": [
    {
      "id": "https://example.org/canvas/page1",
      "type": "Canvas",
      "label": { "en": ["Page 1"] },
      "height": 1000,
      "width": 750,
      "items": [
        {
          "id": "https://example.org/page/page1/annopage",
          "type": "AnnotationPage",
          "items": [
            {
              "id": "https://example.org/page/page1/anno",
              "type": "Annotation",
              "motivation": "painting",
              "body": {
                "id": "https://example.org/iiif/page1/full/max/0/default.jpg",
                "type": "Image",
                "format": "image/jpeg",
                "service": [
                  {
                    "id": "https://example.org/iiif/page1",
                    "type": "ImageService3",
                    "profile": "level2"
                  }
                ]
              },
              "target": "https://example.org/canvas/page1"
            }
          ]
        }
      ]
    }
  ]
}
```

#### Canvas
Virtual container representing a view of the object (page, image, time segment) with defined dimensions.
- **Spatial**: Uses `height` and `width` properties
- **Temporal**: Uses `duration` property  
- **Mixed**: Can have all three dimensions

#### Range
Defines structural sections within an object (chapters, movements, articles).
```json
{
  "id": "https://example.org/range/chapter1",
  "type": "Range",
  "label": { "en": ["Chapter 1"] },
  "items": [
    { "id": "https://example.org/canvas/page1", "type": "Canvas" },
    { "id": "https://example.org/canvas/page2", "type": "Canvas" }
  ]
}
```

#### Annotation & Annotation Page
Content is associated with Canvases through Annotations collected in Annotation Pages.
- **Painting motivation**: Content that is part of the Canvas (images, video, audio)
- **Supplementing motivation**: Content derived from the Canvas (transcriptions, translations)
- **Other motivations**: Commentary, tags, etc.

### Essential Properties

#### Required Properties
- **id**: HTTP(S) URI identifier
- **type**: Resource class (Collection, Manifest, Canvas, etc.)
- **label**: Human-readable name (internationalized)

#### Key Descriptive Properties
- **metadata**: Array of label/value pairs for display
- **summary**: Brief description
- **thumbnail**: Representative image(s)
- **provider**: Institution/organization information
- **rights**: License or rights statement URI
- **requiredStatement**: Text that must be displayed (attribution)

#### Technical Properties
- **height/width**: Pixel dimensions for images, aspect ratio for Canvas
- **duration**: Time length in seconds
- **format**: MIME type (e.g., "image/jpeg")
- **profile**: Schema or functionality description
- **viewingDirection**: Display order (left-to-right, right-to-left, etc.)
- **behavior**: Presentation hints (paged, continuous, individuals, etc.)

#### Structural Properties
- **items**: Ordered list of child resources
- **structures**: Top-level Ranges for table of contents
- **annotations**: Commentary Annotation Pages

### Language Internationalization
Properties like `label`, `summary`, and `metadata` use language maps:
```json
{
  "label": {
    "en": ["English Title"],
    "fr": ["Titre Français"],
    "none": ["No Language"]
  }
}
```

### Behavior Values
Control presentation and navigation:

| Behavior | Applies To | Description |
|----------|------------|-------------|
| `auto-advance` | Collections, Manifests, Canvases, Ranges | Automatically proceed to next item |
| `no-auto-advance` | Collections, Manifests, Canvases, Ranges | Do not auto-advance (default) |
| `paged` | Collections, Manifests, Ranges | Page-turning interface |
| `continuous` | Collections, Manifests, Ranges | Virtually stitch views together |
| `individuals` | Collections, Manifests, Ranges | Distinct objects/views (default) |
| `unordered` | Collections, Manifests, Ranges | No inherent order |
| `facing-pages` | Canvases | Canvas shows both parts of opening |
| `sequence` | Ranges | Alternative ordering of Canvases |
| `hidden` | Annotations, etc. | Not rendered by default |

### Viewing Directions
- `left-to-right` (default)
- `right-to-left` 
- `top-to-bottom`
- `bottom-to-top`

---

## Practical Integration Examples

## Practical Integration Examples

### Image API + Presentation API Workflow
1. **Presentation API** provides structure and metadata via Manifests
2. **Image API** delivers actual image content with manipulation capabilities
3. **Annotations** link Image API resources to Canvas positions

```json
{
  "id": "https://example.org/canvas/page1",
  "type": "Canvas",
  "height": 1000,
  "width": 750,
  "items": [{
    "id": "https://example.org/annopage/page1",
    "type": "AnnotationPage",
    "items": [{
      "id": "https://example.org/annotation/page1-image",
      "type": "Annotation",
      "motivation": "painting",
      "body": {
        "id": "https://example.org/iiif/page1/full/max/0/default.jpg",
        "type": "Image",
        "format": "image/jpeg",
        "service": [{
          "id": "https://example.org/iiif/page1",
          "type": "ImageService3",
          "profile": "level2"
        }]
      },
      "target": "https://example.org/canvas/page1"
    }]
  }]
}
```

### Image API Examples

### General Examples
```
# Full image at maximum size, default quality, JPEG format
https://example.org/image-service/abcd1234/full/max/0/default.jpg

# Square region, scaled to 200px width
https://example.org/image-service/abcd1234/square/200,/0/default.jpg

# Specific region by pixels, 50% scale, 90° rotation
https://example.org/image-service/abcd1234/125,15,120,140/pct:50/90/color.png

# Region by percentage, best fit 300x200
https://example.org/image-service/abcd1234/pct:25,25,50,50/!300,200/0/gray.jpg

# Image information document
https://example.org/image-service/abcd1234/info.json
```

### Riksarkivet (Swedish National Archives) Examples

**IIIF Image API 3.0:**
```
# Base URL patterns
https://lbiiif.riksarkivet.se/{image-id}/{region}/{size}/{rotation}/{quality}.jpg
https://lbiiif.riksarkivet.se/v3/{image-id}/{region}/{size}/{rotation}/{quality}.jpg

# Full image examples
https://lbiiif.riksarkivet.se/arkis!R0001216_00005/full/max/0/default.jpg

# Square crop
https://lbiiif.riksarkivet.se/arkis!R0001216_00005/square/max/0/default.jpg

# Region by pixels (x=300, y=300, width=100, height=100)
https://lbiiif.riksarkivet.se/arkis!R0001216_00005/300,300,100,100/max/0/default.jpg

# Scale to fixed width (300px)
https://lbiiif.riksarkivet.se/arkis!R0001216_00005/full/300,/0/default.jpg

# Scale to fixed height (500px)
https://lbiiif.riksarkivet.se/arkis!R0001216_00005/full/,500/0/default.jpg

# Scale to exact dimensions (may distort aspect ratio)
https://lbiiif.riksarkivet.se/arkis!R0001216_00005/full/500,300/0/default.jpg

# 90-degree clockwise rotation
https://lbiiif.riksarkivet.se/arkis!R0001216_00005/full/max/90/default.jpg

# 90-degree rotation with horizontal flip
https://lbiiif.riksarkivet.se/arkis!R0001216_00005/full/max/!90/default.jpg
```

**IIIF Presentation API:**
```
# Manifest for a specific resource
https://lbiiif.riksarkivet.se/{identifier}/manifest

# Example manifest
https://lbiiif.riksarkivet.se/arkis!R0000480/manifest

# Collections (hierarchical organization)
https://lbiiif.riksarkivet.se/collection/riksarkivet
https://lbiiif.riksarkivet.se/collection/amnesomraden  # Subject areas
https://lbiiif.riksarkivet.se/collection/tid           # Time periods

# Collection by archive unit PID
https://lbiiif.riksarkivet.se/collection/arkiv/2Yz2ClKdn2VMeUXQcoZOO6
```

**IIIF Content Search:**
```
# Search within a volume
https://lbiiif.riksarkivet.se/search/arkis!40008511?q=kaffe
https://lbiiif.riksarkivet.se/search/arkis!A0068583?q=juveler
```

### Universal Examples (Any IIIF Server)

## Key Implementation Notes

- Parameters must be in exact order: region/size/rotation/quality.format
- All special characters in identifiers must be URI encoded
- Operations are applied in parameter order: extract region → scale → rotate → adjust quality → convert format
- Servers SHOULD support CORS on image responses
- If region extends beyond image bounds, crop at edges rather than adding empty space
- Zero-dimension regions should return 400 Bad Request

## Error Handling and Rate Limiting

Common HTTP status codes:
- `400 Bad Request` - Invalid parameters
- `403 Forbidden` - Missing rights marking or access denied
- `404 Not Found` - Image/resource not found
- `429 Too Many Requests` - Rate limit exceeded (check X-RateLimit-* headers)
- `501 Not Implemented` - Feature not supported

## CORS Configuration

For external applications, configure CORS headers:
```
# Request header
Origin: https://yourdomain.com

# Response header
Access-Control-Allow-Origin: https://yourdomain.com
```

**Reverse Proxy Setup (recommended for external services):**

Apache HTTP Server:
```apache
ProxyPass /iiif/ https://lbiiif.riksarkivet.se/
ProxyPassReverse /iiif/ https://lbiiif.riksarkivet.se/
Header always set Access-Control-Allow-Origin "*"
```

Nginx:
```nginx
location /iiif/ {
    proxy_pass https://lbiiif.riksarkivet.se/;
    add_header Access-Control-Allow-Origin "*";
}
```

## Programming Examples

### Python: Working with IIIF Manifests and Images
```python
import requests
import json

# Fetch and parse a IIIF Manifest
def get_manifest(manifest_url):
    response = requests.get(manifest_url)
    return response.json()

# Extract all image URLs from a manifest
def extract_image_urls(manifest):
    image_urls = []
    for canvas in manifest.get('items', []):
        for annotation_page in canvas.get('items', []):
            for annotation in annotation_page.get('items', []):
                if annotation.get('motivation') == 'painting':
                    body = annotation.get('body', {})
                    if body.get('type') == 'Image':
                        image_urls.append(body.get('id'))
    return image_urls

# Get image service base URL from image URL
def get_image_service_url(image_url):
    # Remove the Image API parameters to get base service URL
    # e.g., https://example.org/iiif/img1/full/max/0/default.jpg
    # becomes https://example.org/iiif/img1
    parts = image_url.split('/')
    return '/'.join(parts[:-4])  # Remove /region/size/rotation/quality.format

# Generate thumbnail URL using Image API
def create_thumbnail_url(image_url, width=150, height=150):
    service_url = get_image_service_url(image_url)
    return f"{service_url}/full/!{width},{height}/0/default.jpg"

# Example usage
manifest_url = "https://lbiiif.riksarkivet.se/arkis!R0000480/manifest"
manifest = get_manifest(manifest_url)
images = extract_image_urls(manifest)

for img_url in images:
    thumb_url = create_thumbnail_url(img_url)
    print(f"Original: {img_url}")
    print(f"Thumbnail: {thumb_url}")
```

### Python: Download Images from Riksarkivet Collection
```python
import requests
import sys
import json
import zipfile
import re
import os

URL_BASE = 'https://lbiiif.riksarkivet.se/collection/arkiv/'

def process_collection(collection, zip_file):
    for item in collection.get('items', []):
        res = requests.get(item.get('id'))
        if res.status_code == 200:
            item_json = res.json()
            if item.get('type') == 'Collection':
                process_collection(item_json, zip_file)
            else:
                process_manifest(item_json, zip_file)

def process_manifest(manifest, zip_file):
    for canvas in manifest.get('items', []):
        for annotation_page in canvas.get('items', []):
            for annotation in annotation_page.get('items', []):
                image_url = annotation.get('body', {}).get('id')
                if image_url:
                    regex = re.compile('.*\!(.*)\/full.*')
                    result = regex.match(image_url)
                    if result:
                        image_id = result.group(1)
                        try:
                            file_name = f'{image_id}.jpg'
                            print(f'Processing {file_name}')
                            download_file(image_url, file_name)
                            zip_file.write(file_name, file_name)
                            os.remove(file_name)
                        except Exception as e:
                            print(e)

def download_file(url, file_name):
    with requests.get(url, stream=True) as r:
        r.raise_for_status()
        with open(file_name, 'wb') as f:
            for chunk in r.iter_content(chunk_size=8192):
                f.write(chunk)

def main():
    if len(sys.argv) > 1:
        pid = sys.argv[1]
        res = requests.get(f'{URL_BASE}{pid}')
        if res.status_code == 200:
            collection = res.json()
            with zipfile.ZipFile(f'{pid}.zip', 'w') as zip_file:
                process_collection(collection, zip_file)
    else:
        print('Usage: download.py <pid>')

if __name__ == "__main__":
    main()
```

### JavaScript: IIIF Viewer Integration
```javascript
// Universal Viewer integration
const manifestUri = 'https://lbiiif.riksarkivet.se/arkis!R0000480/manifest';
const uv = new UV.createUV('#uv-container', { 
  manifestUri: manifestUri,
  configUri: '/uv-config.json'
});

// Mirador viewer integration
const mirador = Mirador.viewer({
  id: 'mirador-container',
  windows: [{
    manifestId: manifestUri,
    canvasId: 'https://lbiiif.riksarkivet.se/arkis!R0000480/canvas/1'
  }]
});

// OpenSeadragon with IIIF Image service
const viewer = OpenSeadragon({
  id: 'osd-container',
  tileSources: {
    '@context': 'http://iiif.io/api/image/3/context.json',
    '@id': 'https://lbiiif.riksarkivet.se/arkis!R0000480_00001',
    'profile': 'level1'
  }
});

// Fetch manifest and display metadata
async function displayManifest(manifestUrl) {
  const response = await fetch(manifestUrl);
  const manifest = await response.json();
  
  // Display basic info
  const title = manifest.label?.en?.[0] || manifest.label?.sv?.[0] || 'Untitled';
  const summary = manifest.summary?.en?.[0] || manifest.summary?.sv?.[0] || '';
  
  document.getElementById('title').textContent = title;
  document.getElementById('summary').textContent = summary;
  
  // Display metadata
  const metadataContainer = document.getElementById('metadata');
  manifest.metadata?.forEach(item => {
    const label = item.label?.en?.[0] || item.label?.sv?.[0] || '';
    const value = item.value?.en?.[0] || item.value?.sv?.[0] || '';
    
    const div = document.createElement('div');
    div.innerHTML = `<strong>${label}:</strong> ${value}`;
    metadataContainer.appendChild(div);
  });
}
```

### Finding Image IDs from Archive Units
1. Get archive unit PID from search interface
2. Fetch collection data: `https://lbiiif.riksarkivet.se/collection/arkiv/{pid}`
3. Extract manifest URLs from `items` array
4. Parse image IDs from manifest image URLs

### IIIF Presentation API Structure

**Collection Response Example:**
```json
{
  "id": "https://lbiiif.riksarkivet.se/collection/arkiv/2Yz2ClKdn2VMeUXQcoZOO6",
  "type": "Collection",
  "label": { "sv": ["1 (1654-1721) - Handlingar rörande förhandlingar..."] },
  "summary": { "sv": ["Referenskod: SE/RA/2113/2113.2/1"] },
  "items": [
    {
      "id": "https://lbiiif.riksarkivet.se/arkis!R0000480/manifest",
      "type": "Manifest",
      "label": { "sv": ["1 (1654-1721) - R0000480 - Handlingar..."] }
    }
  ]
}
```

**Hierarchy:**
- **Collection** → Contains other Collections or Manifests
- **Manifest** → Contains Canvases (individual pages/images)
- **Canvas** → Contains image annotations with Image API URLs

## Common Use Cases

### Image API
- **Thumbnails** - Quick generation of preview images at specific sizes
- **Deep zoom viewers** - Requesting tiles and regions for interactive viewing
- **Responsive images** - Serving appropriate sizes for different devices
- **Image analysis** - Extracting specific regions for processing
- **Print quality** - High-resolution downloads with rotation/cropping

### Presentation API
- **Digital libraries** - Organizing books, manuscripts, and documents
- **Museum collections** - Presenting artworks with metadata and context
- **Archives** - Hierarchical organization of historical materials
- **Educational platforms** - Structured learning materials with annotations
- **Cultural heritage** - Multi-language, multi-institutional content sharing

### Combined Workflows
- **Reading room interfaces** - Full manuscripts with page-turning and zoom
- **Annotation tools** - Transcription and commentary systems
- **Comparative viewing** - Side-by-side analysis of similar materials
- **Mobile apps** - Responsive cultural heritage exploration
- **Research platforms** - Advanced search and analysis tools

## Implementation Notes

### Content Delivery Best Practices
- Use Image API for dynamic image manipulation and delivery
- Use Presentation API for metadata, structure, and viewing instructions
- Combine both APIs for complete digital object presentation
- Implement proper caching strategies for performance
- Consider CDN deployment for global access

### Client Application Patterns
1. **Parse Manifest** → Extract structure and metadata
2. **Render Canvas** → Display individual views/pages
3. **Load Images** → Use Image API services for content
4. **Handle Annotations** → Process transcriptions, translations, comments
5. **Navigate Structure** → Use Ranges for table of contents
6. **Apply Behaviors** → Follow presentation hints (paging, auto-advance, etc.)

### Data Flow
```
Collection → Manifest → Canvas → Annotation → Image Service
     ↓          ↓         ↓          ↓            ↓
  Hierarchy  Metadata  Viewport  Association   Pixels
```

## Implementation Variations

### Riksarkivet (Swedish National Archives) Specifics
**Technical Implementation:**
- **Compliance Level**: Image API Level 1 (basic features)
- **Supported Formats**: JPEG only (`.jpg`)
- **Supported Quality**: `default` only
- **Version Support**: Both IIIF 2.0 and 3.0 APIs
- **Content Types**: 
  - Images: `content-type: image/jpeg`
  - Manifests: `content-type: application/json`
- **Access Rights**: Public digitized archives older than 110 years
- **Rate Limiting**: Enforced with `X-RateLimit-*` headers

**Content Organization:**
- Collections organized by subject (`amnesomraden`) and time (`tid`)
- Archive units identified by persistent IDs (PIDs)
- Manifests correspond to volumes or individual items
- Search integration with full-text OCR content

**API Endpoints:**
- Image API: `https://lbiiif.riksarkivet.se/`
- Collections: `https://lbiiif.riksarkivet.se/collection/`
- Search: `https://lbiiif.riksarkivet.se/search/`

### General IIIF Implementation Patterns

**Compliance Levels (Image API):**
- **Level 0**: Static images with limited manipulation
- **Level 1**: Basic resize, rotation, quality options
- **Level 2**: Full specification support with advanced features

**Common Institution Patterns:**
- **Museums**: Focus on high-quality images with rich metadata
- **Libraries**: Emphasis on text materials with OCR and search
- **Archives**: Hierarchical organization with finding aids
- **Universities**: Research-focused with annotation tools

**Supported IIIF APIs (Typical Implementations):**
-**Image API 3.0/2.0** - Core image delivery (universal)
-**Presentation API 3.0** - Metadata and structure (most institutions)
-**Content Search API 1.0** - Full-text search (text-heavy collections)
- ⚠️ **Authentication API 1.0** - Access control (restricted content)
- ⚠️ **Change Discovery API 1.0** - Update notifications (large institutions)

### Server Technology Stacks

**Popular IIIF Server Software:**
- **Cantaloupe** - Java-based image server (Image API)
- **IIPImage** - C++ high-performance server
- **Loris** - Python image server
- **RIIIF** - Ruby implementation
- **Omeka S** - Content management with IIIF support
- **Samvera/Hyrax** - Digital repository platform
- **DSpace** - Institutional repository with IIIF modules

**Cloud Solutions:**
- **IIIF Hosting** - Managed IIIF services
- **AWS/Azure/GCP** - Serverless IIIF implementations
- **ContentDM** - OCLC's hosted digital collections platform

## Integration with Viewers

### Popular IIIF-Compatible Viewers

**Full-Featured Viewers:**
- **Universal Viewer** - Complete presentation with navigation and metadata
- **Mirador** - Advanced viewer with workspace and comparison features
- **Tify** - Vue.js-based viewer for modern web applications

**Specialized Viewers:**
- **OpenSeadragon** - High-performance pan/zoom for images
- **Leaflet-IIIF** - Map-style tile viewer for large images
- **Annona** - Lightweight annotation-focused viewer

**Implementation Examples:**
```javascript
// Universal Viewer (comprehensive)
const manifestUri = 'https://lbiiif.riksarkivet.se/arkis!R0000480/manifest';
const uv = new UV.createUV('#uv', { manifestUri: manifestUri });

// Mirador (research-focused)
const mirador = Mirador.viewer({
  id: 'mirador',
  windows: [{ manifestId: manifestUri }],
  workspaceControlPanel: { enabled: true }
});

// OpenSeadragon (image-focused)
const viewer = OpenSeadragon({
  id: 'osd',
  tileSources: 'https://example.org/iiif/image1/info.json'
});
```

### Mobile and Responsive Considerations
- Progressive image loading for bandwidth optimization
- Touch-friendly zoom and pan interactions  
- Adaptive metadata display for small screens
- Offline capability for downloaded content
- Platform-specific apps (iOS/Android) using IIIF APIs