Пример #1
0
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)
Пример #2
0
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:
        params = web.Parse.params(identifier, **kwargs)
        tile = iiif.IIIF.render(resolve(identifier), **params)
        tile.save(cache_path, tile.mime)
        return send_file(tile, mimetype=tile.mime)
    except:
        abort(400)
Пример #3
0
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:
        params = web.Parse.params(identifier, **kwargs)
        tile = iiif.IIIF.render(resolve(identifier), **params)
        tile.save(cache_path, tile.mime)
        return send_file(tile, mimetype=tile.mime)
    except:
        abort(400)
Пример #4
0
def iiif(**kwargs):
    """ Return a cached tile or a real tile"""
    cache_id = web.urihash(request.url)
    cached_tile = os.path.join(PATH, 'cache', '%s' % cache_id)
    params = web.Parse.params(**kwargs)
    path = resolve(params.get('identifier'))
    if os.path.isfile(cached_tile):
        print "returning cached image"
        return send_file(open(cached_tile), mimetype="image/jpeg")

    else:
        with IIIF.render(path, **params) as tile:
            print cache_id
            tile.save(cached_tile)
            return send_file(tile, mimetype=tile.mime)
Пример #5
0
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)
Пример #6
0
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)