Пример #1
0
def test_iiif_image_key(image_object):
    """Test retrieval of image."""
    key = u'{}:{}:{}'.format(
        image_object.bucket_id,
        image_object.version_id,
        image_object.key,
    )
    assert key == iiif_image_key(image_object)
    assert key == iiif_image_key(dict(
        bucket=image_object.bucket_id,
        version_id=image_object.version_id,
        key=image_object.key,
    ))
Пример #2
0
def test_iiif_image_key(image_object):
    """Test retrieval of image."""
    key = '{}:{}:{}'.format(
        image_object.bucket_id,
        image_object.version_id,
        image_object.key,
    )
    assert key == iiif_image_key(image_object)
    assert key == iiif_image_key(dict(
        bucket=image_object.bucket_id,
        version_id=image_object.version_id,
        key=image_object.key,
    ))
Пример #3
0
def record_thumbnail(pid, record, thumbnail_size, **kwargs):
    """Provide easy access to the thumbnail of a record for predefined sizes.

    We consider the thumbnail of the record as the first image in the files
    iterator or the one set as the default.
    """
    if not has_record_perm(current_user, record, 'read-files'):
        abort(404)
    cached_thumbnails = current_app.config['CACHED_THUMBNAILS']
    if thumbnail_size not in cached_thumbnails:
        abort(400, 'The selected thumbnail has not been cached')
    selected = None
    thumbnail_size = cached_thumbnails[thumbnail_size]
    for file in record.files:
        if(file['type'] not in ['jpg', 'png', 'tif', 'tiff']):
            continue
        elif not selected:
            selected = file
        elif file['default']:
            selected = file
            break
    if selected:
        return IIIFImageAPI().get(
                version='v2',
                uuid=str(iiif_image_key(selected)),
                region='full',
                size=thumbnail_size,
                rotation='0',
                quality='default',
                image_format=file['type'])
    else:
        abort(404, 'This record has no thumbnails')
Пример #4
0
    def get_iiif_urls(self, record=None, pid=None, file=None, **kwargs):
        for identifier_maker in self.identifier_makers:
            data = identifier_maker(record=record,
                                    pid=pid,
                                    file=file,
                                    **kwargs)
            if data is None:
                continue
            if isinstance(data, str):
                return make_iiif_url(data)
            elif isinstance(data, (list, tuple)):
                return [make_iiif_url(x) for x in data]
            elif isinstance(data, dict):
                return {k: make_iiif_url(v) for k, v in data}
            else:
                raise Exception('Unhandled IIIF identifier type %s' %
                                type(data))

        obj = file.get_version()
        if not obj.mimetype.startswith('image/'):
            return
        return make_iiif_url(iiif_image_key(obj))
Пример #5
0
def test_ui_iiif_image_url(appctx, image_object):
    """Test retrieval of image info."""
    assert iiif_image_url(uuid=iiif_image_key(image_object)).endswith(
        ui_iiif_image_url(image_object)
    )
Пример #6
0
def test_ui_iiif_image_url(appctx, image_object):
    """Test retrieval of image info."""
    assert iiif_image_url(uuid=iiif_image_key(image_object)).endswith(
        ui_iiif_image_url(image_object)
    )