How to create manifest.json dynamically for Universal Viewer

517 Views Asked by At

I am working on showing Universal Viewer from my .Net web application. I have many JP2 images stored in IIP Image server. Now, I want to create manifest.json to feed my Universal Viewer. Is it possible to create it dynamically with canvases for all the images stored in image server. Please help me.

Thanks

2

There are 2 best solutions below

1
Vitaliy S On

The IIIF [International Image Interoperability Framework] API defines a web service that returns an image in response to a standard HTTP or HTTPS request. The URI may indicate the area, size, rotation, quality characteristics and format of the requested image.

For a server, you can deploy your own server, such as a Loris server or IIPImage

0
G M On

For IIIF presentation API 2.0 and earlier versions there is this excellent tool for Python iiif-prezi which is a reference implementation. Maybe you can use IronPython for using it in your C# project. Basically, you create a manifest object:

manifest = factory.manifest(label="Example Manifest")
seq = manifest.sequence()  # unlabeled, anonymous sequence

And then you can add the canvases dynamically:

for p in range(10):
    # Create a canvas with uri slug of page-1, and label of Page 1
    cvs = seq.canvas(ident="page-%s" % p, label="Page %s" % p)

    # Create an annotation on the Canvas
    anno = cvs.annotation()

    # Add Image: http://www.example.org/path/to/image/api/p1/full/full/0/native.jpg
    img = anno.image("p%s" % p, iiif=True)

    # Set image height and width, and canvas to same dimensions
    imagefile = "/path/to/images/p%s.jpg" % p
    img.set_hw_from_file(imagefile) 

API 3.0

I built my own Python module for dealing with 3.0 IIIF presentation API which is called IIIFpres, you might consider giving it a try:

from IIIFpres import iiifpapi3
iiifpapi3.BASE_URL = "https://iiif.io/api/cookbook/recipe/0009-book-1"
manifest = iiifpapi3.Manifest()
manifest.set_id(extendbase_url="manifest.json")
manifest.add_label("en","Simple Manifest - Book")
manifest.add_behavior("paged")

data = (("Blank page",3204,4613,"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f18","/full/max/0/default.jpg"),
        ("Frontispiece",3186,4612,"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f19","/full/max/0/default.jpg"),
        ("Title page",3204,4613,"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f20","/full/max/0/default.jpg"),
        ("Blank page",3174,4578,"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f21","/full/max/0/default.jpg"),
        ("Bookplate",3198,4632,"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f22","/full/max/0/default.jpg"),)

for idx,d in enumerate(data):
    idx+=1 
    canvas = iiifpapi3.Canvas()
    canvas.set_id(extendbase_url=["canvas","p%s"%idx]) # in this case we use the base url
    canvas.set_height(d[2])
    canvas.set_width(d[1])
    canvas.add_label("en",d[0])
    annopage = iiifpapi3.AnnotationPage()
    annopage.set_id(extendbase_url=["page","p%s"%idx,"1"])
    annotation = iiifpapi3.Annotation(target=canvas.id)
    annotation.set_id(extendbase_url=["annotation","p%s-image"%str(idx).zfill(4)])
    annotation.set_motivation("painting")
    annotation.body.set_id("".join(d[3:]))
    annotation.body.set_type("Image")
    annotation.body.set_format("image/jpeg")
    annotation.body.set_width(d[1])
    annotation.body.set_height(d[2])
    s = iiifpapi3.service()
    s.set_id(d[3])
    s.set_type("ImageService3")
    s.set_profile("level1")
    annotation.body.add_service(s)
    # remember to add the item to their container!
    annopage.add_item(annotation)
    canvas.add_item(annopage)
    manifest.add_item(canvas)

manifest.json_save("manifest.json")