コード例 #1
0
  @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;
  }
コード例 #2
0
  @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;
  }
コード例 #3
0
  @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);
    }
  }
コード例 #4
0
 private URI buildGeneratedImagePath(ImageStyle imageStyle, URI uri) throws URISyntaxException {
   return new URI(
       uri.getScheme()
           + "://"
           + GENERATED_IMAGES_PATH
           + "/"
           + imageStyle.getKey()
           + uri.getPath());
 }
コード例 #5
0
  /**
   * 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;
  }