Class AdaptiveImageHelper

java.lang.Object
com.day.cq.wcm.foundation.AdaptiveImageHelper

public class AdaptiveImageHelper extends Object
Helper class for working with adaptive images.
  • Constructor Details

    • AdaptiveImageHelper

      public AdaptiveImageHelper()
  • Method Details

    • getQualityFromString

      public static AdaptiveImageHelper.Quality getQualityFromString(String imageQualityString)
      Lookup Quality value from a String.
      Parameters:
      imageQualityString - image quality
      Returns:
      a Quality value for the requested String if it exists.
    • scaleThisImage

      public Layer scaleThisImage(Image image, int newWidth, int newHeight, Style style) throws RepositoryException, IOException
      Scales the given image to the dimensions specified by newWidth and newHeight. The scaling algorithm will always scale the image in such a way that no white space will visible around the image. This means that in any case where the dimensions are not the exact aspect ratio of the image, some cropping will occur. Once the image has been cropped it will be adjusted so the center of the cropped dimension is still centered.
      Parameters:
      image - image
      newWidth - desired width
      newHeight - specify 0 to scale based on width and keep the current aspect ratio
      style - style data including user defined crop and rotation
      Returns:
      scaled (and/or cropped) image layer
      Throws:
      RepositoryException - if image can not be loaded
      IOException - if image can not be loaded
    • applyStyleDataToImage

      public Layer applyStyleDataToImage(Image image, Style style) throws RepositoryException, IOException
      Applies style data to the given image, including crop and rotation.
      Parameters:
      image - image
      style - style
      Returns:
      Layer with style data applied.
      Throws:
      RepositoryException - if image can not be loaded
      IOException - if image can not be loaded
    • renderScaledPlaceholderImage

      public static Layer renderScaledPlaceholderImage(int width, int height)
      Renders a white rectangular layer with the given dimensions.
      Parameters:
      width - requested width
      height - requested height
      Returns:
      Empty layer of a given dimensions.