Package com.day.cq.wcm.foundation
Class AdaptiveImageHelper
java.lang.Object
com.day.cq.wcm.foundation.AdaptiveImageHelper
Helper class for working with adaptive images.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDefines values for a number of common qualities. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapplyStyleDataToImage(Image image, Style style) Applies style data to the given image, including crop and rotation.static AdaptiveImageHelper.QualitygetQualityFromString(String imageQualityString) Lookup Quality value from a String.static LayerrenderScaledPlaceholderImage(int width, int height) Renders a white rectangular layer with the given dimensions.scaleThisImage(Image image, int newWidth, int newHeight, Style style) Scales the given image to the dimensions specified by newWidth and newHeight.
-
Constructor Details
-
AdaptiveImageHelper
public AdaptiveImageHelper()
-
-
Method Details
-
getQualityFromString
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- 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 loadedIOException- 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- imagestyle- style- Returns:
- Layer with style data applied.
- Throws:
RepositoryException- if image can not be loadedIOException- if image can not be loaded
-
renderScaledPlaceholderImage
Renders a white rectangular layer with the given dimensions.- Parameters:
width- requested widthheight- requested height- Returns:
- Empty layer of a given dimensions.
-