def info(identifier):
    try:
        path, mediatype = ia_resolver(identifier)
    except ValueError:
        abort(404)
    try:
        domain = '%siiif/%s' % (request.url_root, identifier)
        info = web.info(domain, path)
        return ldjsonify(info)
    except:
        abort(400)  # , "Invalid item, may actually be collection")
def view(identifier):
    domain = request.args.get('domain', request.url_root)
    uri = '%s%s' % (domain, identifier)
    try:
        path, mediatype = ia_resolver(identifier)
    except ValueError:
        abort(404)
    if mediatype == 'image' or '$' in identifier:
        return render_template('viewer.html', domain=domain,
                               info=web.info(uri, path))
    return render_template('reader.html', domain=request.base_url)
def info(identifier):
    try:
        path, mediatype = ia_resolver(identifier)
    except ValueError:
        abort(404)
    try:
        domain = '%s%s' % (purify_domain(request.url_root), identifier)
        info = web.info(domain, path)
        return ldjsonify(info)
    except:
        abort(400)  # , "Invalid item, may actually be collection")
def view(identifier):
    domain = purify_domain(request.args.get('domain', request.url_root))
    uri = '%s%s' % (domain, identifier)
    page = request.args.get('page', None)
    citation = request.args.get('citation', None)

    try:
        path, mediatype = ia_resolver(identifier)
    except ValueError:
        abort(404)
    if mediatype == 'image' or '$' in identifier:
        return render_template('viewer.html', domain=domain,
                               info=web.info(uri, path))
    return render_template('reader.html', domain=request.base_url, page=page, citation=citation)
def image_processor(identifier, **kwargs):
    cache_path = os.path.join(cache_root, web.urihash(request.path))

    if os.path.exists(cache_path):
        mime = iiif.type_map[kwargs.get('fmt')]['mime']
        return send_file(cache_path, mimetype=mime)

    try:
        path, _ = ia_resolver(identifier)
    except ValueError:
        abort(404)
    try:
        params = web.Parse.params(identifier, **kwargs)
        tile = iiif.IIIF.render(path, **params)
        tile.save(cache_path, tile.mime)
        return send_file(tile, mimetype=tile.mime)
    except Exception as e:
        abort(400)  # , "Invalid tiling parameter: %s" % e)
def image_processor(identifier, **kwargs):
    cache_path = os.path.join(cache_root, web.urihash(request.path))

    if os.path.exists(cache_path):
        mime = iiif.type_map[kwargs.get('fmt')]['mime']
        return send_file(cache_path, mimetype=mime)

    try:
        path, _ = ia_resolver(identifier)
    except ValueError:
        abort(404)
    try:
        params = web.Parse.params(identifier, **kwargs)
        tile = iiif.IIIF.render(path, **params)
        tile.save(cache_path, tile.mime)
        return send_file(tile, mimetype=tile.mime)
    except Exception as e:
        abort(400)  # , "Invalid tiling parameter: %s" % e)
def image_processor(identifier, **kwargs):
    cache_path = os.path.join(cache_root, web.urihash(request.path))

    if os.path.exists(cache_path):
        mime = iiif.type_map[kwargs.get('fmt')]['mime']
        return send_file(cache_path, mimetype=mime)

    identifiers = identifier.split(',') if ',' in identifier else [identifier]
    sprite_tiles = []
    for _id in identifiers:
        try:
            path, _ = ia_resolver(_id)
        except:
            abort(404)
        try:
            params = web.Parse.params(_id, **kwargs)
            tile = iiif.IIIF.render(path, **params)
            tile_cache_path = os.path.join(
                cache_root, web.urihash(request.path.replace(identifier, _id)))
            tile.seek(0)
            tile.save(tile_cache_path, tile.mime)
            sprite_tiles.append(tile)
        except Exception as e:
            abort(404)

    if len(sprite_tiles) == 1:
        tile = sprite_tiles[0]
    else:
        tile = iiif.IIIF.format(sprite_concat(sprite_tiles),
                                fmt=kwargs.get('fmt'))
        tile.seek(0)
        print(cache_path)
        tile.save(cache_path, tile.mime)

    try:
        tile.seek(0)
        return send_file(tile, mimetype=tile.mime)
    except Exception as e:
        abort(400)