How to use @iiif/vocabulary - 10 common examples

To help you get started, we’ve selected a few @iiif/vocabulary examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github edsilv / biiif / Utils.ts View on Github external
public static async getFileDimensions(type: string, file: string, canvasJson: any, annotationJson: any): Promise {

        console.log(chalk.green('getting file dimensions for: ') + file);

        if (!Utils.isJsonFile(file)) {
            switch (type.toLowerCase()) {
                // if it's an image, get the width and height and add to the annotation body and canvas
                case ExternalResourceType.IMAGE :
                    const image: any = await Jimp.read(file);
                    const width: number = image.bitmap.width;
                    const height: number = image.bitmap.height;
                    canvasJson.width = Math.max(canvasJson.width || 0, width);
                    canvasJson.height = Math.max(canvasJson.height || 0, height);
                    annotationJson.body.width = width;
                    annotationJson.body.height = height;
                    break;
                // if it's a sound, get the duration and add to the canvas
                case ExternalResourceType.SOUND :
                case ExternalResourceType.VIDEO :
                    try {
                        const info: any = await ffprobe(file, { path: ffprobeStatic.path });
                        if (info && info.streams && info.streams.length) {
                            const duration: number = Number(info.streams[0].duration);
                            canvasJson.duration = duration;
github edsilv / biiif / Canvas.ts View on Github external
if (!annotationJson.body.format) {
                    delete annotationJson.body.format;
                    console.warn(chalk.yellow('unable to determine format of ' + file));
                }
                
                if (yml.label) {
                    annotationJson.body.label = Utils.getLabel(yml.label);
                    canvasJson.label = Utils.getLabel(yml.label);
                } else {
                    annotationJson.body.label = Utils.getLabel(this.infoYml.label);
                }

                // if the annotation is an image and the id points to an info.json
                // add an image service pointing to the info.json
                if (annotationJson.body.type && annotationJson.body.type.toLowerCase() === ExternalResourceType.IMAGE && extname(annotationJson.body.id) === '.json') {
                    const service: any = Utils.cloneJson(imageServiceBoilerplate);
                    service[0].id = annotationJson.body.id.substr(0, annotationJson.body.id.lastIndexOf('/'));
                    annotationJson.body.service = service;
                }

                // if there's a value, and we're using a recognised motivation (except painting)
                if (yml.value && this._config.annotation.motivations[motivation] && motivation !== Utils.normaliseType(AnnotationMotivation.PAINTING)) {
                    annotationJson.body.value = yml.value;
                }

                if (yml.value && !Utils.isURL(yml.value) && annotationJson.body.type) {
                    // get the path to the annotated file
                    const dirName: string = dirname(file);
                    let path: string = join(dirName, yml.value);
                    path = Utils.normaliseFilePath(path);
                    await Utils.getFileDimensions(annotationJson.body.type, path, canvasJson, annotationJson)
github edsilv / biiif / Utils.ts View on Github external
console.log(chalk.green('getting file dimensions for: ') + file);

        if (!Utils.isJsonFile(file)) {
            switch (type.toLowerCase()) {
                // if it's an image, get the width and height and add to the annotation body and canvas
                case ExternalResourceType.IMAGE :
                    const image: any = await Jimp.read(file);
                    const width: number = image.bitmap.width;
                    const height: number = image.bitmap.height;
                    canvasJson.width = Math.max(canvasJson.width || 0, width);
                    canvasJson.height = Math.max(canvasJson.height || 0, height);
                    annotationJson.body.width = width;
                    annotationJson.body.height = height;
                    break;
                // if it's a sound, get the duration and add to the canvas
                case ExternalResourceType.SOUND :
                case ExternalResourceType.VIDEO :
                    try {
                        const info: any = await ffprobe(file, { path: ffprobeStatic.path });
                        if (info && info.streams && info.streams.length) {
                            const duration: number = Number(info.streams[0].duration);
                            canvasJson.duration = duration;
                        }
                    } catch {
                        console.warn(`ffprobe couldn't load ${file}`);
                    }
                    
                    break;
            }
        }
    }
github edsilv / biiif / Utils.ts View on Github external
if (!Utils.isJsonFile(file)) {
            switch (type.toLowerCase()) {
                // if it's an image, get the width and height and add to the annotation body and canvas
                case ExternalResourceType.IMAGE :
                    const image: any = await Jimp.read(file);
                    const width: number = image.bitmap.width;
                    const height: number = image.bitmap.height;
                    canvasJson.width = Math.max(canvasJson.width || 0, width);
                    canvasJson.height = Math.max(canvasJson.height || 0, height);
                    annotationJson.body.width = width;
                    annotationJson.body.height = height;
                    break;
                // if it's a sound, get the duration and add to the canvas
                case ExternalResourceType.SOUND :
                case ExternalResourceType.VIDEO :
                    try {
                        const info: any = await ffprobe(file, { path: ffprobeStatic.path });
                        if (info && info.streams && info.streams.length) {
                            const duration: number = Number(info.streams[0].duration);
                            canvasJson.duration = duration;
                        }
                    } catch {
                        console.warn(`ffprobe couldn't load ${file}`);
                    }
                    
                    break;
            }
        }
    }
github edsilv / biiif / Canvas.ts View on Github external
annotationJson.body.label = Utils.getLabel(yml.label);
                    canvasJson.label = Utils.getLabel(yml.label);
                } else {
                    annotationJson.body.label = Utils.getLabel(this.infoYml.label);
                }

                // if the annotation is an image and the id points to an info.json
                // add an image service pointing to the info.json
                if (annotationJson.body.type && annotationJson.body.type.toLowerCase() === ExternalResourceType.IMAGE && extname(annotationJson.body.id) === '.json') {
                    const service: any = Utils.cloneJson(imageServiceBoilerplate);
                    service[0].id = annotationJson.body.id.substr(0, annotationJson.body.id.lastIndexOf('/'));
                    annotationJson.body.service = service;
                }

                // if there's a value, and we're using a recognised motivation (except painting)
                if (yml.value && this._config.annotation.motivations[motivation] && motivation !== Utils.normaliseType(AnnotationMotivation.PAINTING)) {
                    annotationJson.body.value = yml.value;
                }

                if (yml.value && !Utils.isURL(yml.value) && annotationJson.body.type) {
                    // get the path to the annotated file
                    const dirName: string = dirname(file);
                    let path: string = join(dirName, yml.value);
                    path = Utils.normaliseFilePath(path);
                    await Utils.getFileDimensions(annotationJson.body.type, path, canvasJson, annotationJson)
                }
               
                canvasJson.items[0].items.push(annotationJson); 
            }));
github edsilv / biiif / Canvas.ts View on Github external
let directoryName: string = '';

            // if the canvas is being generated from a canvas directory (starts with an _)
            if (this._isCanvasDirectory()) {
                directoryName = dirname(file);
                directoryName = directoryName.substr(directoryName.lastIndexOf('/'));
            }
            
            const fileName: string = basename(file);
            const id: string = urljoin(this.url.href, directoryName, fileName);

            if (defaultPaintingExtension) {
                defaultPaintingExtension = defaultPaintingExtension[0];
                const annotationJson: any = Utils.cloneJson(annotationBoilerplate);
                annotationJson.id = urljoin(canvasJson.id, 'annotation', canvasJson.items[0].items.length);
                annotationJson.motivation = Utils.normaliseType(AnnotationMotivation.PAINTING);
                annotationJson.target = canvasJson.id;
                annotationJson.body.id = id;
                annotationJson.body.type = defaultPaintingExtension.type;
                annotationJson.body.format = defaultPaintingExtension.format;
                annotationJson.body.label = Utils.getLabel(this.infoYml.label);
                canvasJson.items[0].items.push(annotationJson);
                await Utils.getFileDimensions(defaultPaintingExtension.type, file, canvasJson, annotationJson);                
            }
        }));
    }
github edsilv / biiif / Utils.ts View on Github external
const thumbnailJson: any = Utils.cloneJson(thumbnailBoilerplate);
            thumbnailJson[0].id = Utils.mergePaths(directory.url, Utils.getVirtualFilePath(thumbnail, directory));
            json.thumbnail = thumbnailJson;
        } else if (directory.generateThumbs) {
            // there isn't a thumbnail in the directory, so we'll need to generate it.
            
            // if debugging: jimp item.getitem is not a function
            // generate thumbnail
            if (json.items && json.items.length && json.items[0].items) {
                // find an annotation with a painting motivation of type image.
                const items: any[] =  json.items[0].items;

                for (let i = 0; i < items.length; i++) {
                    const item: any = items[i];
                    const body: any = item.body;
                    if (body && item.motivation === Utils.normaliseType(AnnotationMotivation.PAINTING)) {
                        // is it an image? (without an info.json)
                        if (body.type.toLowerCase() === ExternalResourceType.IMAGE && !Utils.isJsonFile(body.id)) {

                            let imageName: string = body.id.substr(body.id.lastIndexOf('/'));
                            if (imageName.includes('#')) {
                                imageName = imageName.substr(0, imageName.lastIndexOf('#'));
                            }                            
                            const imagePath: string = Utils.normaliseFilePath(join(fp, imageName));
                            let pathToThumb: string = Utils.normaliseFilePath(join(dirname(imagePath), 'thumb.'));

                            // todo: this currently assumes that the image to generate a thumb from is within the directory, 
                            // but it may be in an assets folder and painted by a custom annotation.
                            // see canvas-with-dimensions-manifest.js
                            if (this._config.settings.jimpEnabled && await Utils.fileExists(imagePath)) {
                                const image: any = await Jimp.read(imagePath);
                                const thumb: any = image.clone();
github UniversalViewer / universalviewer / src / Viewer.ts View on Github external
//     extension.name = Extension.VIRTEX;
            //     return extension;
            // }
        };

        this._extensionRegistry = {};

        this._extensionRegistry[ExternalResourceType.CANVAS] = {
            load: this._extensions[Extension.OSD]
        };

        this._extensionRegistry[ExternalResourceType.IMAGE] = {
            load: this._extensions[Extension.OSD]
        };

        this._extensionRegistry[ExternalResourceType.MOVING_IMAGE] = {
            load: this._extensions[Extension.MEDIAELEMENT]
        };

        this._extensionRegistry[ExternalResourceType.PHYSICAL_OBJECT] = {
            load: this._extensions[Extension.VIRTEX]
        };

        this._extensionRegistry[ExternalResourceType.SOUND] = {
            load: this._extensions[Extension.MEDIAELEMENT]
        };

        this._extensionRegistry[RenderingFormat.PDF] = {
            load: this._extensions[Extension.PDF]
        };

        // presentation 3
github UniversalViewer / universalviewer / src / Viewer.ts View on Github external
load: this._extensions[Extension.OSD]
        };

        this._extensionRegistry[ExternalResourceType.IMAGE] = {
            load: this._extensions[Extension.OSD]
        };

        this._extensionRegistry[ExternalResourceType.MOVING_IMAGE] = {
            load: this._extensions[Extension.MEDIAELEMENT]
        };

        this._extensionRegistry[ExternalResourceType.PHYSICAL_OBJECT] = {
            load: this._extensions[Extension.VIRTEX]
        };

        this._extensionRegistry[ExternalResourceType.SOUND] = {
            load: this._extensions[Extension.MEDIAELEMENT]
        };

        this._extensionRegistry[RenderingFormat.PDF] = {
            load: this._extensions[Extension.PDF]
        };

        // presentation 3

        this._extensionRegistry[MediaType.JPG] = {
            load: this._extensions[Extension.OSD]
        };

        this._extensionRegistry[MediaType.PDF] = {
            load: this._extensions[Extension.PDF]
        };
github UniversalViewer / universalviewer / src / Viewer.ts View on Github external
// presentation 3

        this._extensionRegistry[MediaType.JPG] = {
            load: this._extensions[Extension.OSD]
        };

        this._extensionRegistry[MediaType.PDF] = {
            load: this._extensions[Extension.PDF]
        };

        this._extensionRegistry[MediaType.AUDIO_MP4] = {
            load: this._extensions[Extension.AV]
        };

        this._extensionRegistry[MediaType.VIDEO_MP4] = {
            load: this._extensions[Extension.AV]
        };

        this._extensionRegistry[MediaType.WEBM] = {
            load: this._extensions[Extension.AV]
        };

        this._extensionRegistry[MediaType.THREEJS] = {
            load: this._extensions[Extension.VIRTEX]
        };

        this._extensionRegistry[MediaType.MP3] = {
            load: this._extensions[Extension.AV]
        };

        this._extensionRegistry[MediaType.M3U8] = {