Ejemplo n.º 1
0
def get_page_lines(book_id, page_id):
    lines = repository.get_lines(book_id, page_id)
    if lines is None:
        raise ApiException(
            "Could not find lines for page '{}' in book '{}'".format(
                page_id, book_id), 404)
    fac = ManifestFactory()
    fac.set_base_prezi_uri(flask.request.url_root[:-1] + '/iiif/' + book_id +
                           '/' + page_id)
    annotation_list = fac.annotationList(ident=book_id + '/' + page_id)
    # FIXME: Workaround for a really stupid bug in iiif-prezi:
    # The library sets .resources as a class-attribute, which is why:
    #   - it will not get serialized during toJSON
    #   - multiple instances share their resources
    annotation_list.resources = []
    for idx, (text, x, y, w, h) in enumerate(lines):
        anno = annotation_list.annotation(ident='line-{}'.format(idx))
        anno.text(text=text)
        anno.on = (get_canvas_id(book_id, page_id) +
                   "#xywh={},{},{},{}".format(x, y, w, h))
    out_data = annotation_list.toJSON(top=True)
    if not annotation_list.resources:
        # NOTE: iiif-prezi strips empty lists from the resulting JSON,
        #       so we have to add the empty list ourselves...
        out_data['resources'] = []
    return flask.jsonify(out_data)
Ejemplo n.º 2
0
 def test10_set_hw_from_file_image_magick(self):
     mf = ManifestFactory()
     self.assertNotEqual( mf.whichid, '' ) #Expect to find ImageMagick
     self.assertRaises( ConfigurationError, mf.image, 'name' )
     mf.set_base_image_uri( 'testimages' )
     img = mf.image('an_image')
     self.assertEqual( img.set_hw_from_file('testimages/nci-vol-2303-72.jpg'), None )
     self.assertEqual( img.width, 648 )
     self.assertEqual( img.height, 432 )
Ejemplo n.º 3
0
def build_manifest(book_id, book_path, metadata, pages):
    fac = ManifestFactory()
    base_url = flask.request.url_root[:-1]
    fac.set_base_prezi_uri(base_url +
                           flask.url_for('get_book_manifest', book_id=book_id))
    fac.set_base_image_uri(base_url + '/iiif/image/v2')
    fac.set_iiif_image_info(2.0, 2)
    manifest = fac.manifest(label=book_id)
    manifest.set_description("Automatically generated from HOCR")
    seq = manifest.sequence(ident='0')
    for idx, (page_id, img_path, width, height) in enumerate(pages):
        canvas = seq.canvas(ident=page_id, label='Page {}'.format(idx))
        anno = canvas.annotation(ident=page_id)
        img = anno.image('{}:{}'.format(book_id, page_id), iiif=True)
        img.set_hw(height, width)
        canvas.height = img.height
        canvas.width = img.width
        canvas.annotationList(
            base_url +
            flask.url_for('get_page_lines', book_id=book_id, page_id=page_id),
            label="Transcribed Text")
    if not seq.canvases:
        logger.error("{} has no images!".format(book_path))
        return None
    else:
        return manifest
Ejemplo n.º 4
0
def generate(coll):
    metadata = get_metadata()

    mf = ManifestFactory()
    mf.set_base_prezi_uri(MANIFEST_BASE)
    mf.set_base_image_uri(IMAGE_BASE)
    mf.set_iiif_image_info(2.0, 0)

    manifest = None
    seq = None
    page_num = 0

    for folder in glob("data/%s/*" % coll):
        jpegs = glob(folder + "/*.jpg")
        jpegs.sort()
        if len(jpegs) == 0:
            continue

        folder_name = os.path.basename(folder)
        item_id = "%s-%s" % (coll, folder_name)

        folder_metadata = metadata.get(item_id, {})
        title = folder_metadata.get('Title', item_id)
        manifest = mf.manifest(label=title)

        desc = folder_metadata.get('Description/Summary')
        if desc:
            manifest.set_description(desc)

        manifest.set_metadata(folder_metadata)

        seq = manifest.sequence()
        page_num = 0

        for jpeg in jpegs:

            image_info = generate_tiles(jpeg)
            if not image_info:
                break

            page_num += 1
            id = BASE_URL + "/%s/%s/%s" % (coll, folder_name, page_num)

            canvas = seq.canvas(ident=id + "/canvas",
                                label=os.path.basename(jpeg).replace(
                                    '.jpg', ''))
            canvas.thumbnail = get_thumbnail(image_info)

            rel_path = image_info['@id'].replace(IMAGE_BASE, '')

            anno = canvas.annotation(ident=id + "/annotation")
            image = anno.image(ident=rel_path, iiif=True)
            image.height = image_info['height']
            image.width = image_info['width']

            canvas.height = image.height
            canvas.width = image.width

        write_manifest(manifest, coll, item_id)
Ejemplo n.º 5
0
 def test01_init(self):
     mf = ManifestFactory()
     self.assertEqual( mf.context_uri, 'http://iiif.io/api/presentation/2/context.json' )
     self.assertFalse( mf.add_lang )
     # simple instance variable sets
     mf = ManifestFactory( mdbase="aa", imgbase="bb", mddir="tests" )
     self.assertEqual( mf.metadata_base, 'aa/' )
     self.assertEqual( mf.default_base_image_uri, 'bb' )
     self.assertEqual( mf.metadata_dir, 'tests/' )
     # language setting
     mf = ManifestFactory(lang='cy')
     self.assertTrue( mf.add_lang )
     self.assertRaises( ConfigurationError, ManifestFactory, version='bad' )
Ejemplo n.º 6
0
    def test12_collection_embed_flag(self):
        mf = ManifestFactory(mdbase="aa", imgbase="bb")
        parent = mf.collection(label="parent")
        child = parent.collection(label="child")
        gchild = child.collection(label="grandchild")
        child._embed = True
        js = parent.toJSON()
        self.assertEqual(js['collections'][0]['collections'][0]['label'],
                         'grandchild')

        child._embed = False
        js = parent.toJSON()
        self.assertFalse(js['collections'][0].get('collections', False))
Ejemplo n.º 7
0
 def test09_set_hw_from_iiif(self):
     mf = ManifestFactory()
     mf.set_base_image_uri('file:tests/testdata')
     img = mf.image('image1', iiif=True)
     self.assertEqual(img.set_hw_from_iiif(), None)
     self.assertEqual(img.width, 3000)
     self.assertEqual(img.height, 4000)
     # Error cases
     img._identifier = ""
     self.assertRaises(ConfigurationError, img.set_hw_from_iiif)
     img._identifier = "image-does-not-exist"
     self.assertRaises(ConfigurationError, img.set_hw_from_iiif)
     img._identifier = "image2_bad"
     self.assertRaises(ConfigurationError, img.set_hw_from_iiif)
Ejemplo n.º 8
0
def make_manifest_json(image_pages, thumbnail_images, identifier, page=None):
    fac = ManifestFactory()
    fac.set_base_prezi_uri(get_manifest_url(''))
    fac.set_debug("error")
    if page is None:
        page = {
            "title": image_pages[0]['title'],
            "extract": "(single wikimedia image)"
        }
    manifest = fac.manifest(ident=identifier, label=page['title'])
    manifest.description = sanitise(page['extract'])
    sequence = manifest.sequence(ident="normal", label="default order")
    for image_page in image_pages:
        page_id = image_page.get('pageid', None)
        wiki_info = image_page.get('imageinfo', [None])[0]
        if wiki_info is not None and wiki_info['mime'] == "image/jpeg":
            canvas = sequence.canvas(ident='c%s' % page_id,
                                     label=image_page['title'])
            canvas.set_hw(wiki_info['thumbheight'], wiki_info['thumbwidth'])
            set_canvas_metadata(wiki_info, canvas)
            anno = canvas.annotation(ident='a%s' % page_id)
            img = anno.image(ident=wiki_info['thumburl'], iiif=False)
            img.set_hw(wiki_info['thumbheight'], wiki_info['thumbwidth'])
            thumb_page = thumbnail_images.get(str(page_id), None)
            if thumb_page is not None:
                thumb_info = thumb_page['imageinfo'][0]
                canvas.thumbnail = fac.image(ident=thumb_info['thumburl'])
                canvas.thumbnail.format = "image/jpeg"
                canvas.thumbnail.set_hw(thumb_info['thumbheight'],
                                        thumb_info['thumbwidth'])
    return manifest.toJSON(top=True)
Ejemplo n.º 9
0
	def buildFactory(self, version):
		"""Return instance of ManifestFactory for correct API version."""
		if self.require_version:
			fac = ManifestFactory(version=self.require_version)
		else:
			fac = ManifestFactory(version=version)
		self.debug_stream = io.StringIO()
		fac.set_debug("warn")
		fac.set_debug_stream(self.debug_stream)
		return fac
Ejemplo n.º 10
0
def get_page_lines(book_id, page_id):
    lines = repository.get_lines(book_id, page_id)

    fac = ManifestFactory()
    base_url = app.config.get('BASE_URL', 'http://localhost:5000')
    fac.set_base_metadata_uri(base_url + '/iiif/' + book_id)
    annotation_list = fac.annotationList(ident=page_id)
    for idx, (text, x, y, w, h) in enumerate(lines):
        anno = annotation_list.annotation(ident='line-{}'.format(idx))
        anno.text(text=text)
        anno.on = (get_canvas_id(book_id, page_id) +
                   "#xywh={},{},{},{}".format(x, y, w, h))
    out_data = annotation_list.toJSON(top=True)
    if not annotation_list.resources:
        # NOTE: iiif-prezi strips empty list from the resulting JSON,
        #       so we have to add the empty list ourselves...
        out_data['resources'] = []
    return flask.jsonify(out_data)
Ejemplo n.º 11
0
    def __init__(self, generate_image_pyramid: bool = True):
        """Inits ImageProcessor and configures manifest factory.

        :param generate_image_pyramid:if True, pyramid map will be generated. Else, only manifest is generated.
        """
        if not os.path.exists(MANIFEST_OUTPUT_DIR):
            os.makedirs(MANIFEST_OUTPUT_DIR)
        self._manifest_factory = ManifestFactory()
        self._manifest_factory.set_base_prezi_uri(MANIFEST_BASE_URL)
        self._manifest_factory.set_base_prezi_dir(MANIFEST_OUTPUT_DIR)
        self._manifest_factory.set_base_image_uri(IMAGE_BASE_URL)
        self._manifest_factory.set_iiif_image_info(2.0, 1)  # Version, ComplianceLevel

        self._image_reader = ImageReader(IMAGE_SOURCE_DIR)

        if generate_image_pyramid:
            self._tile_generator = IIIFStatic(dst=IMAGE_FILE_OUTPUT_DIR, prefix=IMAGE_BASE_URL)

        self._generate_images = generate_image_pyramid
Ejemplo n.º 12
0
def _make_empty_manifest(ident: str, label: str, base_url: str) -> Manifest:
    """Generate an empty IIIF manifest.

    :param ident:       Identifier for the manifest, that is not a URL, but
                        the `<ident>` in `https://..../<ident>/manifest`
    :param label:       Label for the manifest
    :param base_url:    Root URL for the application, e.g. https://example.com
    :returns:           The empty manifest
    """
    manifest_factory = ManifestFactory()
    manifest_ident = f'{base_url}/iiif/{ident}/manifest'
    manifest_factory.set_base_prezi_uri(f'{base_url}/iiif/{ident}')
    manifest_factory.set_base_image_uri(f'{base_url}/iiif/image')
    manifest_factory.set_iiif_image_info('2.0', 0)
    manifest = manifest_factory.manifest(ident=manifest_ident, label=label)
    return manifest
Ejemplo n.º 13
0
    def test11_set_multiple_descriptions(self):
        # XXX Decide if the following should also work
        # m.description = []
        # m.description = "a"
        # m.description = "b"
        # self.assertEqual(m.description, ["a", "b"])
        mf = ManifestFactory(mdbase="aa", imgbase="bb")
        m = mf.manifest('a manifest')
        m.description = ["a", "b"]
        self.assertEqual(m.description, ["a", "b"])

        m.description = []
        m.description = {"en": "fish"}
        self.assertEqual(
            m.description,
            OrderedDict([('@value', 'fish'), ('@language', 'en')]))

        m.description = []
        m.description = ["bar", {"en": "fish"}]
        self.assertEqual(
            m.description,
            ["bar",
             OrderedDict([('@value', 'fish'), ('@language', 'en')])])
Ejemplo n.º 14
0
	def buildFactory(self, version):
		"""Return instance of ManifestFactory for correct API version."""
		if self.require_version:
			fac = ManifestFactory(version=self.require_version)
		else:
			fac = ManifestFactory(version=version)
		self.debug_stream = StringIO.StringIO()
		fac.set_debug("warn")
		fac.set_debug_stream(self.debug_stream)
		return fac
Ejemplo n.º 15
0
def make_manifest_json(image_pages, thumbnail_images, identifier, page=None):
    """Generate the raw json for manifest."""
    fac = ManifestFactory()
    fac.set_base_prezi_uri(identifier)
    fac.set_debug('error')
    if page is None:
        page = {
            "title":
            "Media on Wikimedia Commons with the Category: {}".format(
                CATEGORY_STRING),
            "extract":
            "Generated by the ScienceStories.io API"
        }
    manifest = fac.manifest(ident=identifier, label=page['title'])
    manifest.description = sanitise(page['extract'])
    sequence = manifest.sequence(ident="normal", label="default order")
    for image_page in image_pages:
        page_id = image_page.get('pageid', None)
        wiki_info = image_page.get('imageinfo', [None])[0]
        # TODO: Extend support for more MIME Types
        # Currently universalviewer does not support: "image/tiff"
        verified_mimes = ["image/jpeg", "image/png"]
        if wiki_info is not None and wiki_info['mime'] in verified_mimes:
            canvas = sequence.canvas(ident='c%s' % page_id,
                                     label=image_page['title'])
            canvas.set_hw(wiki_info['thumbheight'], wiki_info['thumbwidth'])
            set_canvas_metadata(wiki_info, canvas)
            anno = canvas.annotation(ident='a%s' % page_id)
            img = anno.image(ident=wiki_info['thumburl'], iiif=False)
            img.set_hw(wiki_info['thumbheight'], wiki_info['thumbwidth'])
            thumb_page = thumbnail_images.get(str(page_id), None)
            if thumb_page is not None:
                thumb_info = thumb_page['imageinfo'][0]
                canvas.thumbnail = fac.image(ident=thumb_info['thumburl'])
                canvas.thumbnail.format = "image/jpeg"
                canvas.thumbnail.set_hw(thumb_info['thumbheight'],
                                        thumb_info['thumbwidth'])
    manifest_serialized = manifest.toJSON(top=True)
    return manifest_serialized
Ejemplo n.º 16
0
imageUrl = config['image_base_url']
manifestUrl = config['manifest_base_url']

# Configure XML namespaces
nss = {'mets': "http://www.loc.gov/METS/",
	   'dc': 'http://purl.org/dc/elements/1.1/',
	   'dcterms': 'http://purl.org/dc/terms/',
	   'dnx': 'http://www.exlibrisgroup.com/dps/dnx',
	   'xsi': 'http://www.w3.org/2001/XMLSchema-instance'}

sigPropsPath = "/mets:mets/mets:amdSec[@ID='%s-amd']/mets:techMD/mets:mdWrap/mets:xmlData/dnx:dnx/dnx:section[@id='significantProperties']"
widthPath = "./dnx:record[./dnx:key[@id='significantPropertiesType']/text()='nisoImage.imageWidth']/dnx:key[@id='significantPropertiesValue']/text()"
heightPath = "./dnx:record[./dnx:key[@id='significantPropertiesType']/text()='nisoImage.imageLength']/dnx:key[@id='significantPropertiesValue']/text()"

# Configure the Manifest factory
fac = ManifestFactory()
fac.set_base_image_uri(imageUrl)
fac.set_iiif_image_conformance(2.0, 2)
# Need to set base manifest directory and url per object

def fetch_mets(identifier):
	url = "%sentity/%s" % (rosetta, identifier)
	resp = requests.get(url, headers={"Authorization":auth})	
	data = resp.content
	dom = etree.XML(data)
	return dom

def fetch_image(identifier, ident, rep, image):

	# Check we don't already have it:
	destDir = "%s%s" % (imageDir, ident)
Ejemplo n.º 17
0
def generate_iiif(images, pdf):
    """Generate IIIF 2.0 static image-service and manifest"""

    # configure manifest factory
    manifest_factory = ManifestFactory()
    manifest_factory.set_base_prezi_dir(str(manifest_path))
    manifest_factory.set_base_prezi_uri("http://localhost:8000")
    manifest_factory.set_base_image_uri("http://localhost:8000/images")
    manifest_factory.set_iiif_image_info(2.0, 1)

    manifest = manifest_factory.manifest(label="Example Manifest from PDF")
    manifest.description = "Sample P2 manifest with images from PDF"
    manifest.set_metadata({"Generated from": pdf})

    # configure tile generator for static assets
    tile_generator = IIIFStatic(dst=str(image_path),
                                prefix="http://localhost:8000/images",
                                tilesize=512,
                                api_version="2.1",
                                extras=['/full/90,/0/default.jpg',
                                        '/full/200,/0/default.jpg'])  # thumbnail for UV

    seq = manifest.sequence()
    idx = 0
    for i in images:
        print(f"processing image {idx}")
        image_id = i.stem

        # create a canvas with an annotation
        canvas = seq.canvas(ident=image_id, label=f"Canvas {idx}")

        # create an annotation on the Canvas
        annotation = canvas.annotation(ident=f"page-{idx}")

        # add an image to the anno
        img = annotation.image(image_id, iiif=True)
        img.service.profile = 'http://iiif.io/api/image/2/level0.json'

        # set image + canvas hw
        img.set_hw_from_file(str(i))
        canvas.height = img.height
        canvas.width = img.width

        # generate image-pyramid
        tile_generator.generate(src=i, identifier=image_id)

        idx = idx + 1

    manifest.toFile(compact=False)
Ejemplo n.º 18
0
"""iiif-prezi example code to build a manifest from a directory of images

"""

from iiif_prezi.factory import ManifestFactory
import os

image_dir = "/path/to/images"
prezi_dir = "/tmp"

fac = ManifestFactory()
fac.set_debug("error")
fac.set_base_image_uri("http://localhost/iiif")
fac.set_base_image_dir(image_dir)
fac.set_iiif_image_info()
fac.set_base_metadata_uri("http://localhost/prezi/")
fac.set_base_metadata_dir(prezi_dir)

mflbl = os.path.split(image_dir)[1].replace("_", " ").title()

mfst = fac.manifest(label=mflbl)
seq = mfst.sequence()
for fn in os.listdir(image_dir):
    ident = fn[:-4]
    title = ident.replace("_", " ").title()
    cvs = seq.canvas(ident=ident, label=title)
    cvs.add_image_annotation(ident, True)

mfst.toFile(compact=False)
Ejemplo n.º 19
0
"""iiif-prezi example code to build a manifest"""

from iiif_prezi.factory import ManifestFactory

imageWidth = 693
imageHeight = 786

identifier = "test"

# Configure the factory
fac = ManifestFactory()
fac.set_base_metadata_uri("http://ids.lib.harvard.edu/iiif/metadata/")
fac.set_base_image_uri("http://ids.lib.harvard.edu/ids/view/" + identifier +
                       '/')
fac.set_iiif_image_conformance(1.1, 1)

# Build the Manifest
mf = fac.manifest(ident="manifest", label="Example Manifest")
mf.set_metadata({"test label": "test value", "next label": "next value"})
mf.attribution = "Provided by the Houghton Library, Harvard University"
mf.viewingHint = "paged"
mf.description = "Description of Manuscript MS Richardson 44 Goes Here"

# And walk through the pages
seq = mf.sequence(ident="normal", label="Normal Order")
for st in range(3):
    # Build the Canvas
    cvs = seq.canvas(ident="c%s" % st, label="Test Canvas %s" % st)
    cvs.set_hw(imageHeight, imageWidth)

    # Build the Image Annotation
Ejemplo n.º 20
0
textUris = [BASEURL + "resources/page1.txt", BASEURL + "resources/page2.txt"]
htmlUris = [BASEURL + "resources/page1.html", BASEURL + "resources/page2.html"]
transcriptions = [[
    "Top of First Page to Display", "Middle of First Page on Angle",
    "Bottom of First Page to Display"
],
                  [
                      "Top of Second Page to Display",
                      "Middle of Second Page on Angle",
                      "Bottom of Second Page on Angle"
                  ]]

line1Dims = "225,70,750,150"

# Configure the factory
fac = ManifestFactory()
fac.set_base_prezi_uri(BASEURL)
fac.set_base_prezi_dir(HOMEDIR)
fac.set_base_image_uri(IMAGE_BASEURL)
fac.set_iiif_image_info(2.0, 1)
fac.set_debug('error')

testInfo = {

    # Done
    1: {
        "title": "Minimum Required Fields"
    },
    2: {
        "title": "Metadata Pairs",
        'mfprops': [('metadata', {
Ejemplo n.º 21
0
"""iiif-prezi example code to build a manifest from a directory of images

"""

from iiif_prezi.factory import ManifestFactory
import os

image_dir = "/path/to/images"
prezi_dir = "/tmp"

fac = ManifestFactory()
fac.set_debug("error")
fac.set_base_image_uri("http://localhost/iiif")
fac.set_base_image_dir(image_dir)
fac.set_iiif_image_info()
fac.set_base_metadata_uri("http://localhost/prezi/")
fac.set_base_metadata_dir(prezi_dir)

mflbl = os.path.split(image_dir)[1].replace("_", " ").title()

mfst = fac.manifest(label=mflbl)
seq = mfst.sequence()
for fn in os.listdir(image_dir):
	ident = fn[:-4]
	title = ident.replace("_", " ").title()
	cvs = seq.canvas(ident=ident, label=title)
	cvs.add_image_annotation(ident, True)

mfst.toFile(compact=False)
Ejemplo n.º 22
0
 def test03_set_debug(self):
     mf = ManifestFactory()
     self.assertRaises( ConfigurationError, mf.set_debug, 'unkn' )
Ejemplo n.º 23
0
from iiif_prezi.factory import ManifestFactory
import os

prezi_uri = "http://ufdcimages.uflib.ufl.edu/UF/00/07/88/91/00001/"
prezi_dir = "//flvc.fs.osg.ufl.edu/flvc-ufdc/resources/AA/00/00/00/01/00001"
# prezi_dir = "/c/Users/desai.kirti/Desktop/New folder/iiif-pre/tmp"

fac = ManifestFactory()
# fac.set_debug("error")
fac.set_base_image_uri("https://iiif.io/api/image/2.1/")
fac.set_iiif_image_info(2.0, 2)

fac.set_base_prezi_uri(prezi_uri)
fac.set_base_prezi_dir(prezi_dir)

# fac.set_debug("warn") 
# mflbl = os.path.split(image_dir)[1].replace("_", " ").title()

mfst = fac.manifest(label="example")
seq = mfst.sequence()
# for fn in os.listdir(image_dir):
#     ident = fn[:-4]
#     title = ident.replace("_", " ").title()
#     cvs = seq.canvas(ident=ident, label=title)
#     cvs.add_image_annotation(ident, True)

for p in range(1,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
Ejemplo n.º 24
0
"""iiif-prezi example code to build a manifest"""

from iiif_prezi.factory import ManifestFactory

imageWidth = 693
imageHeight = 786

identifier = "test"

# Configure the factory
fac = ManifestFactory()
fac.set_base_metadata_uri("http://ids.lib.harvard.edu/iiif/metadata/")
fac.set_base_image_uri("http://ids.lib.harvard.edu/ids/view/" + identifier + '/')
fac.set_iiif_image_conformance(1.1, 1)

# Build the Manifest
mf = fac.manifest(ident="manifest", label="Example Manifest")
mf.set_metadata({"test label":"test value", "next label":"next value"})
mf.attribution = "Provided by the Houghton Library, Harvard University"
mf.viewingHint = "paged"
mf.description = "Description of Manuscript MS Richardson 44 Goes Here"


# And walk through the pages
seq = mf.sequence(ident="normal", label="Normal Order")
for st in range(3):
	# Build the Canvas
	cvs = seq.canvas(ident="c%s" % st,label="Test Canvas %s" % st)
	cvs.set_hw(imageHeight, imageWidth)

	# Build the Image Annotation
Ejemplo n.º 25
0
from iiif_prezi.factory import ManifestFactory
from openpyxl import load_workbook
import os
import warnings
warnings.simplefilter("ignore")

spreadsheet = load_workbook(filename="McLagan_MSGen1042.xlsx", read_only=True)
sheet = spreadsheet.active

manuscripts = ["MS_Gen_1042_1", "MS_Gen_1042_10", "MS_Gen_1042_100", "MS_Gen_1042_101", "MS_Gen_1042_102", "MS_Gen_1042_103", "MS_Gen_1042_104", "MS_Gen_1042_105", "MS_Gen_1042_106a", "MS_Gen_1042_106b", "MS_Gen_1042_107", "MS_Gen_1042_108", "MS_Gen_1042_109", "MS_Gen_1042_11", "MS_Gen_1042_110", "MS_Gen_1042_111", "MS_Gen_1042_112", "MS_Gen_1042_113", "MS_Gen_1042_114", "MS_Gen_1042_115", "MS_Gen_1042_116", "MS_Gen_1042_117", "MS_Gen_1042_118", "MS_Gen_1042_119", "MS_Gen_1042_12", "MS_Gen_1042_120", "MS_Gen_1042_121", "MS_Gen_1042_122", "MS_Gen_1042_123", "MS_Gen_1042_124", "MS_Gen_1042_125", "MS_Gen_1042_126", "MS_Gen_1042_127", "MS_Gen_1042_128", "MS_Gen_1042_129a", "MS_Gen_1042_129b", "MS_Gen_1042_13", "MS_Gen_1042_130", "MS_Gen_1042_132", "MS_Gen_1042_133", "MS_Gen_1042_134", "MS_Gen_1042_135a", "MS_Gen_1042_135b", "MS_Gen_1042_136", "MS_Gen_1042_137", "MS_Gen_1042_138", "MS_Gen_1042_139", "MS_Gen_1042_14", "MS_Gen_1042_140", "MS_Gen_1042_141", "MS_Gen_1042_142", "MS_Gen_1042_143", "MS_Gen_1042_144", "MS_Gen_1042_145", "MS_Gen_1042_146", "MS_Gen_1042_147", "MS_Gen_1042_148", "MS_Gen_1042_149", "MS_Gen_1042_15", "MS_Gen_1042_150", "MS_Gen_1042_151", "MS_Gen_1042_152", "MS_Gen_1042_153", "MS_Gen_1042_154", "MS_Gen_1042_155", "MS_Gen_1042_156", "MS_Gen_1042_157", "MS_Gen_1042_158", "MS_Gen_1042_159", "MS_Gen_1042_16", "MS_Gen_1042_160", "MS_Gen_1042_161", "MS_Gen_1042_162", "MS_Gen_1042_163", "MS_Gen_1042_164", "MS_Gen_1042_165a", "MS_Gen_1042_165b", "MS_Gen_1042_166", "MS_Gen_1042_167", "MS_Gen_1042_168", "MS_Gen_1042_169", "MS_Gen_1042_17", "MS_Gen_1042_170", "MS_Gen_1042_171", "MS_Gen_1042_172", "MS_Gen_1042_173", "MS_Gen_1042_174", "MS_Gen_1042_175", "MS_Gen_1042_176", "MS_Gen_1042_177", "MS_Gen_1042_178", "MS_Gen_1042_179", "MS_Gen_1042_18", "MS_Gen_1042_180", "MS_Gen_1042_181", "MS_Gen_1042_182", "MS_Gen_1042_183", "MS_Gen_1042_184", "MS_Gen_1042_185", "MS_Gen_1042_186", "MS_Gen_1042_187", "MS_Gen_1042_188", "MS_Gen_1042_189", "MS_Gen_1042_19", "MS_Gen_1042_190", "MS_Gen_1042_191", "MS_Gen_1042_192", "MS_Gen_1042_193", "MS_Gen_1042_194", "MS_Gen_1042_195", "MS_Gen_1042_196", "MS_Gen_1042_197", "MS_Gen_1042_198", "MS_Gen_1042_199", "MS_Gen_1042_2", "MS_Gen_1042_20", "MS_Gen_1042_200", "MS_Gen_1042_201", "MS_Gen_1042_203", "MS_Gen_1042_204", "MS_Gen_1042_205", "MS_Gen_1042_206", "MS_Gen_1042_207", "MS_Gen_1042_208", "MS_Gen_1042_209", "MS_Gen_1042_21", "MS_Gen_1042_210", "MS_Gen_1042_211", "MS_Gen_1042_212", "MS_Gen_1042_213", "MS_Gen_1042_214", "MS_Gen_1042_216", "MS_Gen_1042_217", "MS_Gen_1042_218", "MS_Gen_1042_219", "MS_Gen_1042_22", "MS_Gen_1042_220", "MS_Gen_1042_221", "MS_Gen_1042_222a", "MS_Gen_1042_222b", "MS_Gen_1042_222c", "MS_Gen_1042_223", "MS_Gen_1042_224", "MS_Gen_1042_225", "MS_Gen_1042_226", "MS_Gen_1042_227", "MS_Gen_1042_228", "MS_Gen_1042_229", "MS_Gen_1042_23", "MS_Gen_1042_230", "MS_Gen_1042_231", "MS_Gen_1042_232", "MS_Gen_1042_233", "MS_Gen_1042_234", "MS_Gen_1042_235", "MS_Gen_1042_236", "MS_Gen_1042_237", "MS_Gen_1042_238", "MS_Gen_1042_239", "MS_Gen_1042_24", "MS_Gen_1042_240", "MS_Gen_1042_241", "MS_Gen_1042_242", "MS_Gen_1042_243", "MS_Gen_1042_244", "MS_Gen_1042_245", "MS_Gen_1042_246", "MS_Gen_1042_247", "MS_Gen_1042_248", "MS_Gen_1042_249", "MS_Gen_1042_24a", "MS_Gen_1042_25", "MS_Gen_1042_250", "MS_Gen_1042_251", "MS_Gen_1042_252", "MS_Gen_1042_253", "MS_Gen_1042_254", "MS_Gen_1042_26", "MS_Gen_1042_27", "MS_Gen_1042_28", "MS_Gen_1042_29", "MS_Gen_1042_3", "MS_Gen_1042_30", "MS_Gen_1042_31", "MS_Gen_1042_32", "MS_Gen_1042_33", "MS_Gen_1042_34", "MS_Gen_1042_35", "MS_Gen_1042_36", "MS_Gen_1042_37", "MS_Gen_1042_38", "MS_Gen_1042_39", "MS_Gen_1042_4", "MS_Gen_1042_40", "MS_Gen_1042_41", "MS_Gen_1042_42", "MS_Gen_1042_43", "MS_Gen_1042_44", "MS_Gen_1042_45", "MS_Gen_1042_47", "MS_Gen_1042_48", "MS_Gen_1042_49", "MS_Gen_1042_5", "MS_Gen_1042_50", "MS_Gen_1042_51", "MS_Gen_1042_52", "MS_Gen_1042_53", "MS_Gen_1042_54", "MS_Gen_1042_54a", "MS_Gen_1042_55", "MS_Gen_1042_56", "MS_Gen_1042_57", "MS_Gen_1042_58", "MS_Gen_1042_59", "MS_Gen_1042_60", "MS_Gen_1042_61", "MS_Gen_1042_62", "MS_Gen_1042_63", "MS_Gen_1042_64", "MS_Gen_1042_65", "MS_Gen_1042_66", "MS_Gen_1042_67", "MS_Gen_1042_68", "MS_Gen_1042_69", "MS_Gen_1042_7", "MS_Gen_1042_70", "MS_Gen_1042_71", "MS_Gen_1042_72", "MS_Gen_1042_73", "MS_Gen_1042_74", "MS_Gen_1042_75", "MS_Gen_1042_76", "MS_Gen_1042_77", "MS_Gen_1042_78", "MS_Gen_1042_79", "MS_Gen_1042_79a", "MS_Gen_1042_8", "MS_Gen_1042_80", "MS_Gen_1042_81", "MS_Gen_1042_81a", "MS_Gen_1042_82", "MS_Gen_1042_83", "MS_Gen_1042_84", "MS_Gen_1042_85", "MS_Gen_1042_86", "MS_Gen_1042_87", "MS_Gen_1042_88", "MS_Gen_1042_89", "MS_Gen_1042_9", "MS_Gen_1042_90", "MS_Gen_1042_91", "MS_Gen_1042_92", "MS_Gen_1042_93", "MS_Gen_1042_94", "MS_Gen_1042_95", "MS_Gen_1042_96", "MS_Gen_1042_97", "MS_Gen_1042_98", "MS_Gen_1042_99"]

ms_with_ranges =["MS Gen 1042/10","MS Gen 1042/102","MS Gen 1042/105","MS Gen 1042/106a","MS Gen 1042/106b","MS Gen 1042/109","MS Gen 1042/111","MS Gen 1042/114","MS Gen 1042/115","MS Gen 1042/118","MS Gen 1042/120","MS Gen 1042/122","MS Gen 1042/125","MS Gen 1042/126","MS Gen 1042/129a","MS Gen 1042/129b","MS Gen 1042/13","MS Gen 1042/130","MS Gen 1042/132","MS Gen 1042/135b","MS Gen 1042/136","MS Gen 1042/137","MS Gen 1042/139","MS Gen 1042/14","MS Gen 1042/140","MS Gen 1042/141","MS Gen 1042/142","MS Gen 1042/143","MS Gen 1042/145","MS Gen 1042/146","MS Gen 1042/148","MS Gen 1042/150","MS Gen 1042/151","MS Gen 1042/153","MS Gen 1042/154","MS Gen 1042/156","MS Gen 1042/160","MS Gen 1042/161","MS Gen 1042/162","MS Gen 1042/163","MS Gen 1042/165b","MS Gen 1042/166","MS Gen 1042/167","MS Gen 1042/168","MS Gen 1042/169","MS Gen 1042/170","MS Gen 1042/177","MS Gen 1042/18","MS Gen 1042/180","MS Gen 1042/181","MS Gen 1042/184","MS Gen 1042/185","MS Gen 1042/186","MS Gen 1042/187","MS Gen 1042/19","MS Gen 1042/190","MS Gen 1042/192","MS Gen 1042/193","MS Gen 1042/194","MS Gen 1042/195","MS Gen 1042/199","MS Gen 1042/2","MS Gen 1042/20","MS Gen 1042/200","MS Gen 1042/201","MS Gen 1042/204","MS Gen 1042/205","MS Gen 1042/209","MS Gen 1042/210","MS Gen 1042/211","MS Gen 1042/213","MS Gen 1042/216","MS Gen 1042/219","MS Gen 1042/22","MS Gen 1042/222a","MS Gen 1042/222b","MS Gen 1042/222c","MS Gen 1042/225","MS Gen 1042/226","MS Gen 1042/227","MS Gen 1042/229","MS Gen 1042/23","MS Gen 1042/230","MS Gen 1042/233","MS Gen 1042/235","MS Gen 1042/239","MS Gen 1042/240","MS Gen 1042/241","MS Gen 1042/244","MS Gen 1042/25","MS Gen 1042/26","MS Gen 1042/27","MS Gen 1042/29","MS Gen 1042/3","MS Gen 1042/33","MS Gen 1042/36","MS Gen 1042/39","MS Gen 1042/4","MS Gen 1042/45","MS Gen 1042/47","MS Gen 1042/5","MS Gen 1042/50","MS Gen 1042/51","MS Gen 1042/52","MS Gen 1042/53","MS Gen 1042/54","MS Gen 1042/58","MS Gen 1042/59","MS Gen 1042/61","MS Gen 1042/62","MS Gen 1042/64","MS Gen 1042/67","MS Gen 1042/68","MS Gen 1042/69","MS Gen 1042/70","MS Gen 1042/73","MS Gen 1042/76","MS Gen 1042/77","MS Gen 1042/80","MS Gen 1042/81","MS Gen 1042/82","MS Gen 1042/83","MS Gen 1042/85","MS Gen 1042/87","MS Gen 1042/89","MS Gen 1042/9","MS Gen 1042/90","MS Gen 1042/91","MS Gen 1042/94","MS Gen 1042/96","MS Gen 1042/97","MS Gen 1042/98","MS Gen 1042/99"]

prezi_dir = "/tmp"

fac = ManifestFactory()
fac.set_debug("error")
fac.set_iiif_image_info()
fac.set_base_prezi_uri("https://iiif.gla.ac.uk/")
fac.set_base_prezi_dir(prezi_dir)

ranges_done = []
manifests = []

def save_manifest(ms):
    data = manifest.toString(compact=False)
    fh = open("manifests/" + ms[1] + '.json', mode="w", encoding="utf-8")
    fh.write(data)
    fh.close()
    print('Manifest for ' + ms[0] + ' saved')
Ejemplo n.º 26
0
def main():
    mf = ManifestFactory()
    mf.set_base_prezi_uri(config['hostname'])
    mf.set_iiif_image_info(2.0, 0)

    last_item_id = None
    manifest = None
    seq = None
    page_num = 0

    for row in csv.reader(open("data.csv")):

        # only interested in images
        if row[4].startswith('.') or not row[4].lower().endswith('.jpg'):
            continue

        # unpack the metadata
        site, archive, locator, item_type, filename, title = row[0:6]

        # only processing things with titles
        if not title:
            continue

        # only processing things where we can find the path
        image_path = os.path.join(config["data"], *row[0:5])
        if not os.path.isfile(image_path):
            continue

        title = "%s - %s" % (site, title)
        item_id = slugify(title)

        image_info = generate_tiles(image_path)
        if not image_info:
            break

        # when the title changes that's our queue to write the manifest
        if not manifest or item_id != last_item_id:
            if manifest:
                write_manifest(manifest, item_id)
            manifest = mf.manifest(label=title)
            manifest.location = archive
            manifest.set_metadata({
                "title": title,
                "archive": archive,
                "locator": locator,
                "type": item_type
            })
            seq = manifest.sequence()
            page_num = 0

        # add the image to the manifest sequence

        page_num += 1
        canvas = seq.canvas(ident="page-%s" % page_num,
                            label="Page %s" % page_num)
        canvas.thumbnail = get_thumbnail(image_info)

        anno = canvas.annotation()
        image = anno.image(image_info['@id'], iiif=True)
        image.height = image_info['height']
        image.width = image_info['width']

        canvas.height = image.height
        canvas.width = image.width

        last_item_id = item_id

    # write the last one
    write_manifest(manifest, item_id)
Ejemplo n.º 27
0
"""Simple example for iiif_prezi.factory.ManifestFactory()."""

from iiif_prezi.factory import ManifestFactory

factory = ManifestFactory()
factory.set_base_prezi_uri("http://example.org/iiif/prezi/")
factory.set_base_image_uri("http://example.org/iiif/image/")
factory.set_iiif_image_info(version="2.0", lvl="2")

mf = factory.manifest(label="Manifest")
mf.viewingHint = "paged"

seq = mf.sequence()
for x in range(1):
    cvs = seq.canvas(ident="c%s" % x, label="Canvas %s" % x)
    cvs.set_hw(1000, 1000)
    anno = cvs.annotation()
    img = factory.image("f1r.c", iiif=True)
    img2 = factory.image("f1r", iiif=True)
    chc = anno.choice(img, [img2])

# print(mf.toString(compact=False))
Ejemplo n.º 28
0
IMAGE_BASEURL = "http://iiif.io/api/image/2.1/example/reference/"
imageWidth = 1200
imageHeight = 1800

imageUris = [BASEURL + "resources/page1-full.png", BASEURL + "resources/page2-full.png"]
textUris = [BASEURL + "resources/page1.txt", BASEURL + "resources/page2.txt"]
htmlUris = [BASEURL + "resources/page1.html", BASEURL + "resources/page2.html"]
transcriptions = [ 
	["Top of First Page to Display", "Middle of First Page on Angle", "Bottom of First Page to Display"],
	["Top of Second Page to Display", "Middle of Second Page on Angle", "Bottom of Second Page on Angle"]
]

line1Dims = "225,70,750,150"

# Configure the factory
fac = ManifestFactory()
fac.set_base_prezi_uri(BASEURL)
fac.set_base_prezi_dir(HOMEDIR)
fac.set_base_image_uri(IMAGE_BASEURL)
fac.set_iiif_image_info(2.0, 1)
fac.set_debug('error')

testInfo = {

# Done
1 : {"title": "Minimum Required Fields"},
2 : {"title": "Metadata Pairs", 'mfprops': [('metadata',{'date': 'some date'})]},
3 : {"title": "Metadata Pairs with Languages", 'mfprops': [('metadata', {'date': {'en':'some data','fr':'quelquetemps'}})]},
4 : {"title": "Metadata Pairs with Multiple Values in same Language", 'mfprops':[('metadata',{'date': ['some date', 'some other date']})]},
5 : {"title": "Description field", 'mfprops': [('description',"This is a description")]},
6 : {"title": "Multiple Descriptions", 'mfprops': [('description',["This is one description", {"en":"This is another"}])]},
Ejemplo n.º 29
0
    def get(self, request, *args, **kwargs):
        fec_entity = self.get_object()

        fac = ManifestFactory()
        fac.set_base_prezi_uri(getattr(settings, 'BASE_PREZI_URI', 'http://127.0.0.1:8000/'))

        # Default Image API information
        fac.set_base_image_uri(getattr(settings, 'BASE_IMAGE_URI', 'http://127.0.0.1:8182/iiif/2/'))
        fac.set_iiif_image_info(2.0, 2)
        fac.set_debug("error")

        manifest = fac.manifest(label=fec_entity.title)

        manifest.set_metadata(self.assemble_metadata(fec_entity))
        manifest.viewingDirection = "left-to-right"

        manifest.attribution = 'Radio Free Europe/Free Europe Committee - Encrypted Telex Communication<br/>' \
                               'Vera & Donald Blinken Open Society Archives'

        seq = manifest.sequence()

        for p in range(1, fec_entity.pages + 1):
            # Create a canvas with uri slug of page-p, and label of Page 1
            canvas_id = "fec-%s-page-%s" % (fec_entity.doc_name, str(p))
            cvs = seq.canvas(ident=canvas_id, label="Page %s" % p)
            underscore_idx = fec_entity.doc_name.find('_')

            image_id = urllib.quote_plus(
                "fec/%s/%s_%s_%02d.jpg" % (
                    fec_entity.doc_name[:underscore_idx],
                    fec_entity.doc_name[:underscore_idx],
                    fec_entity.doc_name[underscore_idx + 1:],
                    p
                )
            )

            cvs.set_image_annotation(image_id, iiif=True)

        return self.render_json_response(manifest.toJSON(top=True))
Ejemplo n.º 30
0
 def test01_init(self):
     mf = ManifestFactory()
     self.assertEqual(mf.context_uri,
                      'http://iiif.io/api/presentation/2/context.json')
Ejemplo n.º 31
0
# http://localhost:1080/iipsrv/iipsrv.fcgi?iiif=/imageapi//m0171_0/m0171_0visn20_0001a21.jp2/info.json
from iiif_prezi.factory import ManifestFactory
import os
import pymongo
import glob 
databaseaddress_capitolare_mongo ="mongodb+srv://giacomo:[email protected]/testcapit?retryWrites=true&w=majority"
client = pymongo.MongoClient(databaseaddress_capitolare_mongo)

folder = "imageapi/m0171_0"
image_dir = os.path.join(os.getcwd(),folder)
segnatura_id = os.path.basename(folder)
var = client.capitolare.codici.find_one({'segnatura_idx': segnatura_id})

prezi_dir = "/tmp"

fac = ManifestFactory()
fac.set_debug("error")
fac.set_base_image_uri(os.path.join("http://lezioni.meneghetti.univr.it//",folder))
fac.set_base_image_dir(image_dir)
fac.set_iiif_image_info()
fac.set_base_prezi_uri("http://lezioni.meneghetti.univr.it//manifests/")
fac.set_base_prezi_dir(prezi_dir)

mflbl = os.path.split(image_dir)[1].replace("_", " ").title()

mfst = fac.manifest(label=mflbl)
seq = mfst.sequence()
listadir = glob.glob(folder+"/*.jp2")
for fn in [i for i in os.listdir(image_dir) if i.endswith('.jp2')]:
    ident = fn[:-4]
    title = ident.replace("_", " ").title()
Ejemplo n.º 32
0
class ImageProcessor:
    """Manage generation of IIIF resources from manuscript dictionary."""
    _failed = []

    def __init__(self, generate_image_pyramid: bool = True):
        """Inits ImageProcessor and configures manifest factory.

        :param generate_image_pyramid:if True, pyramid map will be generated. Else, only manifest is generated.
        """
        if not os.path.exists(MANIFEST_OUTPUT_DIR):
            os.makedirs(MANIFEST_OUTPUT_DIR)
        self._manifest_factory = ManifestFactory()
        self._manifest_factory.set_base_prezi_uri(MANIFEST_BASE_URL)
        self._manifest_factory.set_base_prezi_dir(MANIFEST_OUTPUT_DIR)
        self._manifest_factory.set_base_image_uri(IMAGE_BASE_URL)
        self._manifest_factory.set_iiif_image_info(2.0, 1)  # Version, ComplianceLevel

        self._image_reader = ImageReader(IMAGE_SOURCE_DIR)

        if generate_image_pyramid:
            self._tile_generator = IIIFStatic(dst=IMAGE_FILE_OUTPUT_DIR, prefix=IMAGE_BASE_URL)

        self._generate_images = generate_image_pyramid

    def generate_iiif_resources(self, manuscript_data: Iterable[ManuscriptRow]) -> None:
        """Generate static IIIF resources for every manuscript record.

        IIIF resources include image pyramid and manifests.

        :param manuscript_data:list of dictionaries containing manuscript metadata.
        :return:None
        """
        for manuscript in manuscript_data:
            self._process_manuscript(manuscript)

        if self._failed:
            print("Errors encountered processing following manuscripts: ")
            print(*self._failed, sep=", ")

    def _process_manuscript(self, manuscript: ManuscriptRow) -> None:
        mhs_number = manuscript.get(ColumnKeys.MHS_NUMBER)

        # noinspection PyBroadException
        try:
            if Path(os.path.join(MANIFEST_OUTPUT_DIR, f"{mhs_number}.json")).is_file():
                print(f"{mhs_number} already processed. Skipping")
                return

            manifest = self._create_manifest(manuscript)

            self._add_canvases(manuscript, manifest)

            manifest.toFile(compact=False)
        except Exception as e:
            print(f"**Error processing {mhs_number}. {e}")
            self._failed.append(mhs_number)

    def _create_manifest(self, manuscript: ManuscriptRow) -> Manifest:
        mhs_number = manuscript.get(ColumnKeys.MHS_NUMBER)
        alternative_name = manuscript.get(ColumnKeys.ALTERNATIVE_NAME)

        print(f"creating manifest for {mhs_number}")
        manifest = self._manifest_factory.manifest(label=f"{mhs_number} - {alternative_name}", ident=mhs_number)

        # add all non-empty fields as metadata (excluding "No" field as this is just internal id)
        manifest.set_metadata({k: v for (k, v) in manuscript.items() if v and k != ColumnKeys.NO
                               and k != ColumnKeys.COMMENTS})
        manifest.description = manuscript.get(ColumnKeys.COMMENTS)
        return manifest

    def _add_canvases(self, manuscript: ManuscriptRow, manifest: Manifest) -> None:
        manuscript_images = self._image_reader.get_files_for_manuscript(manuscript)
        mhs_number = manuscript.get(ColumnKeys.MHS_NUMBER)

        image_count = len(manuscript_images)

        print(f"creating {image_count} canvases for {mhs_number}..")

        seq = manifest.sequence()

        for p in range(image_count):
            image_id = f"{mhs_number}-{p}"
            start = time.time()
            print(f"processing {image_id}..")
            cvs = seq.canvas(ident=image_id, label=f"Page {p}")

            # Create an annotation on the Canvas
            annotation = cvs.annotation(ident=f"page-{p}")

            # set source of image data
            img = annotation.image(image_id, iiif=True)

            # Set image height and width, and canvas to same dimensions
            image_file = manuscript_images[p]
            img.set_hw_from_file(image_file)
            cvs.height = img.height
            cvs.width = img.width
            self._generate_image_pyramid(image_file, image_id, img.width, img.height)

            end = time.time()
            print(f"processed {image_id} in {end - start} secs")

    def _generate_image_pyramid(self, image_file: str, image_id: str, width: int, height: int) -> None:
        if not self._generate_images:
            return

        self._tile_generator.generate(src=image_file, identifier=image_id)

        # generate a 90-wide thumb for UV (see: https://github.com/UniversalViewer/universalviewer/issues/102)
        self._tile_generator.generate_tile("full", [90, None])

        # generate a 1000-wide /full/ image for UV download
        h = 1000 / (width / height)
        self._tile_generator.generate_tile("full", [1000, h])

        # generate a max-width /full/ image for UV download
        self._tile_generator.generate_tile("full", [width, None])