Search in sources :

Example 1 with ImageContent

use of de.digitalcollections.iiif.model.ImageContent in project box-c by UNC-Libraries.

the class LorisContentService method createCanvas.

private Canvas createCanvas(String path, ContentObjectRecord briefObj) {
    String title = getTitle(briefObj);
    String uuid = jp2Pid(briefObj);
    Canvas canvas = new Canvas(path, title);
    if (StringUtils.isEmpty(uuid)) {
        LOG.warn("No jp2 id was found for {}. IIIF canvas is empty.", briefObj.getId());
        return canvas;
    }
    String canvasPath = URIUtil.join(basePath, "jp2Proxy", uuid, "jp2");
    Datastream fileDs = briefObj.getDatastreamObject(DatastreamType.ORIGINAL_FILE.getId());
    String extent = fileDs.getExtent();
    if (extent != null && !extent.equals("")) {
        String[] imgDimensions = extent.split("x");
        canvas.setHeight(Integer.parseInt(imgDimensions[0]));
        canvas.setWidth(Integer.parseInt(imgDimensions[1]));
    }
    canvas.addIIIFImage(canvasPath, ImageApiProfile.LEVEL_TWO);
    ImageContent thumb = new ImageContent(URIUtil.join(basePath, "services", "api", "thumb", uuid, "large"));
    canvas.addImage(thumb);
    return canvas;
}
Also used : Datastream(edu.unc.lib.boxc.search.api.models.Datastream) ImageContent(de.digitalcollections.iiif.model.ImageContent) Canvas(de.digitalcollections.iiif.model.sharedcanvas.Canvas)

Example 2 with ImageContent

use of de.digitalcollections.iiif.model.ImageContent in project cdmlib by cybertaxonomy.

the class ManifestComposer method createCanvas.

public Optional<Canvas> createCanvas(String onEntitiyType, String onEntityUuid, Media media) throws IOException {
    Canvas canvas;
    MediaRepresentation thumbnailRepresentation = mediaTools.processAndFindBestMatchingRepresentation(media, null, null, 100, 100, thumbnailMimetypes, MediaUtils.MissingValueStrategy.MAX);
    MediaRepresentation fullSizeRepresentation = mediaTools.processAndFindBestMatchingRepresentation(media, null, null, Integer.MAX_VALUE, Integer.MAX_VALUE, null, MediaUtils.MissingValueStrategy.MAX);
    // MediaRepresentation thumbnailRepresentation = MediaUtils.findBestMatchingRepresentation(media, null, null, 100, 100, tumbnailMimetypes, MediaUtils.MissingValueStrategy.MAX);
    if (logger.isDebugEnabled()) {
        logger.debug("fullSizeRepresentation: " + fullSizeRepresentation.getParts().get(0).getUri());
        logger.debug("thumbnailRepresentation: " + thumbnailRepresentation.getParts().get(0).getUri());
    }
    List<ImageContent> thumbnailImageContents;
    List<ImageContent> fullSizeImageContents;
    // FIXME the below only makes sense if the media is an Image!!!!!
    if (fullSizeRepresentation != null) {
        fullSizeImageContents = representationPartsToImageContent(fullSizeRepresentation);
    } else {
        fullSizeImageContents = new ArrayList<>(0);
    }
    if (Objects.equals(fullSizeRepresentation, thumbnailRepresentation)) {
        thumbnailImageContents = fullSizeImageContents;
    } else {
        thumbnailImageContents = representationPartsToImageContent(thumbnailRepresentation);
    }
    if (fullSizeRepresentation == null) {
        return Optional.empty();
    }
    canvas = new Canvas(iiifID(onEntitiyType, onEntityUuid, Canvas.class, "media-" + media.getUuid()));
    for (Language lang : media.getAllTitles().keySet()) {
        LanguageString titleLocalized = media.getAllTitles().get(lang);
        canvas.addLabel(titleLocalized.getText());
    }
    canvas.setLabel(new PropertyValue(media.getTitleCache()));
    canvas.setThumbnails(thumbnailImageContents);
    for (ImageContent image : fullSizeImageContents) {
        canvas.addImage(image);
    }
    // explanation
    if (useThumbnailDimensionsForCanvas && !thumbnailImageContents.isEmpty()) {
        if (thumbnailImageContents.get(0).getHeight() != null && thumbnailImageContents.get(0).getHeight() > 0 && thumbnailImageContents.get(0).getWidth() != null && thumbnailImageContents.get(0).getWidth() > 0) {
            canvas.setHeight(thumbnailImageContents.get(0).getHeight());
            canvas.setWidth(thumbnailImageContents.get(0).getWidth());
        }
    }
    List<MetadataEntry> mediaMetadata = mediaMetaData(media);
    List<MetadataEntry> representationMetadata;
    try {
        representationMetadata = mediaService.readResourceMetadataFiltered(fullSizeRepresentation).entrySet().stream().map(e -> new MetadataEntry(e.getKey(), e.getValue())).collect(Collectors.toList());
        mediaMetadata.addAll(representationMetadata);
    } catch (IOException e) {
        logger.error("Error reading media metadata", e);
    } catch (HttpException e) {
        logger.error("Error accessing remote media resource", e);
    }
    // extractAndAddDesciptions(canvas, mediaMetadata);
    mediaMetadata = deduplicateMetadata(mediaMetadata);
    canvas = addAttributionAndLicense(media, canvas, mediaMetadata);
    orderMedatadaItems(canvas);
    canvas.addMetadata(mediaMetadata.toArray(new MetadataEntry[mediaMetadata.size()]));
    return Optional.of(canvas);
}
Also used : Language(eu.etaxonomy.cdm.model.common.Language) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) ImageContent(de.digitalcollections.iiif.model.ImageContent) Canvas(de.digitalcollections.iiif.model.sharedcanvas.Canvas) MediaRepresentation(eu.etaxonomy.cdm.model.media.MediaRepresentation) PropertyValue(de.digitalcollections.iiif.model.PropertyValue) MetadataEntry(de.digitalcollections.iiif.model.MetadataEntry) HttpException(org.apache.http.HttpException) IOException(java.io.IOException)

Example 3 with ImageContent

use of de.digitalcollections.iiif.model.ImageContent in project cdmlib by cybertaxonomy.

the class ManifestComposer method representationPartsToImageContent.

private List<ImageContent> representationPartsToImageContent(MediaRepresentation representation) {
    List<ImageContent> imageContents = new ArrayList<>();
    for (MediaRepresentationPart part : representation.getParts()) {
        if (part.getUri() != null) {
            ImageContent ic = new ImageContent(part.getUri().toString());
            if (part instanceof ImageFile) {
                ImageFile image = (ImageFile) part;
                if (image.getWidth() != null && image.getWidth() > 0) {
                    ic.setWidth(image.getWidth());
                }
                if (image.getHeight() != null && image.getHeight() > 0) {
                    ic.setHeight(image.getHeight());
                }
                if (representation.getMimeType() != null) {
                    ic.setFormat(MimeType.fromTypename(representation.getMimeType()));
                } else {
                    ic.setFormat(MimeType.MIME_IMAGE);
                }
            }
            imageContents.add(ic);
        }
    }
    return imageContents;
}
Also used : MediaRepresentationPart(eu.etaxonomy.cdm.model.media.MediaRepresentationPart) ImageFile(eu.etaxonomy.cdm.model.media.ImageFile) ImageContent(de.digitalcollections.iiif.model.ImageContent) ArrayList(java.util.ArrayList)

Example 4 with ImageContent

use of de.digitalcollections.iiif.model.ImageContent in project TranskribusCore by Transkribus.

the class IIIFUtils method exportIiifManifest.

public static String exportIiifManifest(TrpDoc doc) throws MalformedURLException, JsonProcessingException {
    String productionBaseUrl = "https://dbis-thure.uibk.ac.at/iiif/2";
    String testBaseUrl = "https://files-test.transkribus.eu/iiif/2/";
    ObjectMapper iiifMapper = new IiifObjectMapper();
    Manifest manifest = new Manifest(testBaseUrl + "" + doc.getId() + "/manifest");
    Sequence sequence = new Sequence(testBaseUrl + "" + doc.getId() + "/sequence");
    // TODO add more metadata to manifest
    manifest.addMetadata("Title", doc.getMd().getTitle());
    if (doc.getMd().getAuthor() != null) {
        manifest.addMetadata("Author", doc.getMd().getAuthor());
    }
    List<TrpPage> pages = doc.getPages();
    List<Canvas> canvasList = new ArrayList<>();
    for (TrpPage page : pages) {
        TrpImage pageImage = page.getImage();
        Canvas canvas = new Canvas(testBaseUrl + "" + page.getKey() + "/canvas/" + page.getPageNr());
        canvas.setWidth(pageImage.getWidth());
        canvas.setHeight(pageImage.getHeight());
        canvas.addIIIFImage(testBaseUrl + "" + pageImage.getKey(), ImageApiProfile.LEVEL_ONE);
        ImageContent thumbnail = new ImageContent(pageImage.getThumbUrl().toString());
        thumbnail.addService(new ImageService(pageImage.getThumbUrl().toString(), ImageApiProfile.LEVEL_ONE));
        canvas.addThumbnail(thumbnail);
        canvas.addSeeAlso(new OtherContent(page.getCurrentTranscript().getUrl().toString(), "application/xml"));
        String annotationId = testBaseUrl + "" + page.getKey() + "/contentAsText/" + page.getPageNr();
        AnnotationList annoList = new AnnotationList(annotationId);
        annoList.addLabel("Text of page " + page.getPageNr());
        canvas.addOtherContent(annoList);
        canvasList.add(canvas);
        try {
            createPageTextAnnotation(annotationId, page);
        } catch (IllegalArgumentException | XPathExpressionException | SAXException | IOException | JAXBException e) {
            e.printStackTrace();
        }
    }
    sequence.setCanvases(canvasList);
    manifest.addSequence(sequence);
    String manifestJson = iiifMapper.writerWithDefaultPrettyPrinter().writeValueAsString(manifest);
    try (PrintWriter out = new PrintWriter("/home/lateknight/Desktop/json/manifest.json")) {
        out.println(manifestJson);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    logger.debug(manifestJson);
    return manifestJson;
}
Also used : TrpPage(eu.transkribus.core.model.beans.TrpPage) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Canvas(de.digitalcollections.iiif.model.sharedcanvas.Canvas) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) Sequence(de.digitalcollections.iiif.model.sharedcanvas.Sequence) IOException(java.io.IOException) Manifest(de.digitalcollections.iiif.model.sharedcanvas.Manifest) ImageService(de.digitalcollections.iiif.model.image.ImageService) AnnotationList(de.digitalcollections.iiif.model.sharedcanvas.AnnotationList) SAXException(org.xml.sax.SAXException) ImageContent(de.digitalcollections.iiif.model.ImageContent) TrpImage(eu.transkribus.core.model.beans.TrpImage) OtherContent(de.digitalcollections.iiif.model.OtherContent) IiifObjectMapper(de.digitalcollections.iiif.model.jackson.IiifObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IiifObjectMapper(de.digitalcollections.iiif.model.jackson.IiifObjectMapper) PrintWriter(java.io.PrintWriter)

Example 5 with ImageContent

use of de.digitalcollections.iiif.model.ImageContent in project DSpace by DSpace.

the class ManifestGenerator method generateResource.

@Override
public Resource<Manifest> generateResource() {
    if (identifier == null) {
        throw new RuntimeException("The Manifest resource requires an identifier.");
    }
    Manifest manifest;
    if (label != null) {
        manifest = new Manifest(identifier, label);
    } else {
        manifest = new Manifest(identifier);
    }
    if (renderings.size() > 0) {
        manifest.setRenderings(renderings);
    }
    if (logo != null) {
        List<ImageContent> logos = new ArrayList<>();
        logos.add(logo);
        manifest.setLogos(logos);
    }
    if (sequence != null) {
        manifest.addSequence(sequence);
    }
    if (ranges.size() > 0) {
        for (Range range : ranges) {
            manifest.addRange(range);
        }
    }
    if (metadata.size() > 0) {
        for (MetadataEntry meta : metadata) {
            manifest.addMetadata(meta);
        }
    }
    if (seeAlso != null) {
        manifest.addSeeAlso(seeAlso);
    }
    if (related != null) {
        manifest.addRelated(related);
    }
    if (searchService != null) {
        manifest.addService(searchService);
    }
    if (license.size() > 0) {
        manifest.setLicenses(license);
    }
    if (description != null) {
        manifest.setDescription(description);
    }
    if (thumbnail != null) {
        manifest.addThumbnail(thumbnail);
    }
    if (viewingHint != null) {
        manifest.addViewingHint(viewingHint);
    }
    return manifest;
}
Also used : ImageContent(de.digitalcollections.iiif.model.ImageContent) ArrayList(java.util.ArrayList) MetadataEntry(de.digitalcollections.iiif.model.MetadataEntry) Manifest(de.digitalcollections.iiif.model.sharedcanvas.Manifest) Range(de.digitalcollections.iiif.model.sharedcanvas.Range)

Aggregations

ImageContent (de.digitalcollections.iiif.model.ImageContent)7 Canvas (de.digitalcollections.iiif.model.sharedcanvas.Canvas)4 MetadataEntry (de.digitalcollections.iiif.model.MetadataEntry)3 Manifest (de.digitalcollections.iiif.model.sharedcanvas.Manifest)3 ArrayList (java.util.ArrayList)3 Sequence (de.digitalcollections.iiif.model.sharedcanvas.Sequence)2 IOException (java.io.IOException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 OtherContent (de.digitalcollections.iiif.model.OtherContent)1 PropertyValue (de.digitalcollections.iiif.model.PropertyValue)1 ImageService (de.digitalcollections.iiif.model.image.ImageService)1 IiifObjectMapper (de.digitalcollections.iiif.model.jackson.IiifObjectMapper)1 AnnotationList (de.digitalcollections.iiif.model.sharedcanvas.AnnotationList)1 Range (de.digitalcollections.iiif.model.sharedcanvas.Range)1 ContentObjectRecord (edu.unc.lib.boxc.search.api.models.ContentObjectRecord)1 Datastream (edu.unc.lib.boxc.search.api.models.Datastream)1 Language (eu.etaxonomy.cdm.model.common.Language)1 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)1 ImageFile (eu.etaxonomy.cdm.model.media.ImageFile)1 MediaRepresentation (eu.etaxonomy.cdm.model.media.MediaRepresentation)1