use of org.mycore.iiif.image.model.MCRIIIFImageTargetRotation in project mycore by MyCoRe-Org.
the class MCRIIIFImageResource method getImage.
@GET
@Path("{" + IDENTIFIER_PARAM + "}/{region}/{size}/{rotation}/{quality}.{format}")
public Response getImage(@PathParam(IMPL_PARAM) String implStr, @PathParam(IDENTIFIER_PARAM) String identifier, @PathParam("region") String region, @PathParam("size") String size, @PathParam("rotation") String rotation, @PathParam("quality") String quality, @PathParam("format") String format) {
try {
MCRIIIFImageImpl impl = getImpl(implStr);
MCRIIIFImageInformation information = impl.getInformation(identifier);
MCRIIIFRegionParser rp = new MCRIIIFRegionParser(region, information.width, information.height);
MCRIIIFImageSourceRegion sourceRegion = rp.parseImageRegion();
MCRIIIFScaleParser sp = new MCRIIIFScaleParser(size, sourceRegion.getX2() - sourceRegion.getX1(), sourceRegion.getY2() - sourceRegion.getY1());
MCRIIIFImageTargetSize targetSize = sp.parseTargetScale();
MCRIIIFRotationParser rotationParser = new MCRIIIFRotationParser(rotation);
MCRIIIFImageTargetRotation parsedRotation = rotationParser.parse();
MCRIIIFImageQuality imageQuality = MCRIIIFImageQuality.fromString(quality);
BufferedImage provide = impl.provide(identifier, sourceRegion, targetSize, parsedRotation, imageQuality, format);
Response.Status status = rp.isCompleteValid() ? Response.Status.OK : Response.Status.BAD_REQUEST;
Response.ResponseBuilder responseBuilder = Response.status(status);
return responseBuilder.header("Link", buildCanonicalURL(impl, identifier)).header("Profile", buildProfileURL()).type("image/" + format).entity((StreamingOutput) outputStream -> ImageIO.write(provide, format, outputStream)).build();
} catch (MCRIIIFImageNotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
} catch (IllegalArgumentException | MCRIIIFUnsupportedFormatException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
} catch (MCRAccessException e) {
return Response.status(Response.Status.FORBIDDEN).entity(e.getMessage()).build();
} catch (Exception e) {
LOGGER.error(() -> "Error while getting Image " + identifier + " from " + implStr + " with region: " + region + ", size: " + size + ", rotation: " + rotation + ", quality: " + quality + ", format: " + format, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
use of org.mycore.iiif.image.model.MCRIIIFImageTargetRotation in project mycore by MyCoRe-Org.
the class MCRIIIFRotationParserTest method testParse.
@Test
public void testParse() throws Exception {
Map<String, MCRIIIFImageTargetRotation> testValues = new Hashtable<>();
testValues.put("0", new MCRIIIFImageTargetRotation(false, 0));
testValues.put("!0", new MCRIIIFImageTargetRotation(true, 0));
testValues.put("90", new MCRIIIFImageTargetRotation(false, 90));
testValues.put("!90", new MCRIIIFImageTargetRotation(true, 90));
testValues.put("180", new MCRIIIFImageTargetRotation(false, 180));
testValues.put("!180", new MCRIIIFImageTargetRotation(true, 180));
testValues.put("270", new MCRIIIFImageTargetRotation(false, 270));
testValues.put("!270", new MCRIIIFImageTargetRotation(true, 270));
testValues.forEach((rotationString, expectedResult) -> Assert.assertEquals(new MCRIIIFRotationParser(rotationString).parse(), expectedResult));
}
Aggregations