@Override public Map<String, URI> getGeneratedImagesPaths(URI uri) throws URISyntaxException { Map<String, URI> generatedImages = new HashMap(); for (ImageStyle imageStyle : imageStyles.values()) { generatedImages.put(imageStyle.getKey(), buildGeneratedImagePath(imageStyle, uri)); } return generatedImages; }
@Override public Map<String, URL> getGeneratedImagesUrls(URI uri) throws Exception { Map<String, URL> generatedImages = new HashMap(); for (ImageStyle imageStyle : imageStyles.values()) { generatedImages.put( imageStyle.getKey(), fileService.getUrl(buildGeneratedImagePath(imageStyle, uri))); } return generatedImages; }
@Async @Override public void processImage(URI uri) throws Exception { File image = fileService.get(uri); final BufferedImage bufferedImage = ImageIO.read(image); for (ImageStyle imageStyle : imageStyles.values()) { BufferedImage styledImage = imageStyle.process(bufferedImage); File imageFile = fileService.create(buildGeneratedImagePath(imageStyle, uri)); ImageIO.write(styledImage, FilenameUtils.getExtension(image.getName()), imageFile); } }
private URI buildGeneratedImagePath(ImageStyle imageStyle, URI uri) throws URISyntaxException { return new URI( uri.getScheme() + "://" + GENERATED_IMAGES_PATH + "/" + imageStyle.getKey() + uri.getPath()); }
/** * Predefined image styles generation * * @return */ private Map<String, ImageStyle> generateImageStyles() { Map<String, ImageStyle> imageStyles = new HashMap(); ImageStyle thumbnailStyle = new ImageStyle(THUMBNAIL_STYLE); thumbnailStyle.addProcessor(new ImageScaleAndCrop(150, 150, false)); imageStyles.put(THUMBNAIL_STYLE, thumbnailStyle); ImageStyle mediumStyle = new ImageStyle(MEDIUM_STYLE); mediumStyle.addProcessor(new ImageScale(490, 0, false)); imageStyles.put(MEDIUM_STYLE, mediumStyle); ImageStyle largeStyle = new ImageStyle(LARGE_STYLE); largeStyle.addProcessor(new ImageScale(1280, 0, false)); imageStyles.put(LARGE_STYLE, largeStyle); ImageStyle responsiveScaledStyle = new ImageStyle(RESPONSIVE_SCALED_STYLE); responsiveScaledStyle.addProcessor(new ImageScale(980, 0, false)); imageStyles.put(RESPONSIVE_SCALED_STYLE, responsiveScaledStyle); return imageStyles; }