Package com.day.cq.wcm.foundation
Class AdaptiveImageHelper
- java.lang.Object
-
- com.day.cq.wcm.foundation.AdaptiveImageHelper
-
public class AdaptiveImageHelper extends java.lang.Object
Helper class for working with adaptive images.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AdaptiveImageHelper.Quality
Defines values for a number of common qualities.
-
Constructor Summary
Constructors Constructor Description AdaptiveImageHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Layer
applyStyleDataToImage(Image image, Style style)
Applies style data to the given image, including crop and rotation.static AdaptiveImageHelper.Quality
getQualityFromString(java.lang.String imageQualityString)
Lookup Quality value from a String.static Layer
renderScaledPlaceholderImage(int width, int height)
Renders a white rectangular layer with the given dimensions.Layer
scaleThisImage(Image image, int newWidth, int newHeight, Style style)
Scales the given image to the dimensions specified by newWidth and newHeight.
-
-
-
Method Detail
-
getQualityFromString
public static AdaptiveImageHelper.Quality getQualityFromString(java.lang.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, java.io.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
- imagenewWidth
- desired widthnewHeight
- specify 0 to scale based on width and keep the current aspect ratiostyle
- style data including user defined crop and rotation- Returns:
- scaled (and/or cropped) image layer
- Throws:
RepositoryException
- if image can not be loadedjava.io.IOException
- if image can not be loaded
-
applyStyleDataToImage
public Layer applyStyleDataToImage(Image image, Style style) throws RepositoryException, java.io.IOException
Applies style data to the given image, including crop and rotation.- Parameters:
image
- imagestyle
- style- Returns:
- Layer with style data applied.
- Throws:
RepositoryException
- if image can not be loadedjava.io.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 widthheight
- requested height- Returns:
- Empty layer of a given dimensions.
-
-