How to use the @iiif/vocabulary/dist-commonjs/.AnnotationMotivation.PAINTING function in @iiif/vocabulary

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 / 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();