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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations