Skip to content

Commit

Permalink
#2490 log usage warning in AdaptiveImageServlet
Browse files Browse the repository at this point in the history
  • Loading branch information
joerghoh committed Apr 27, 2023
1 parent 2c92898 commit 117ef36
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Binary file added bundles/core/jacoco.exec
Binary file not shown.
Expand Up @@ -112,7 +112,11 @@ public class AdaptiveImageServlet extends SlingSafeMethodsServlet {
static final int DEFAULT_RESIZE_WIDTH = 1280;
public static final int DEFAULT_JPEG_QUALITY = 82; // similar to what is the default in com.day.image.Layer#write(...)
public static final int DEFAULT_MAX_SIZE = 3840; // 4K UHD width

private static final Logger LOGGER = LoggerFactory.getLogger(AdaptiveImageServlet.class);
private static final Logger AVOID_USAGE_LOGGER =
LoggerFactory.getLogger(AdaptiveImageServlet.class.getName() + ".AvoidUsage");

private static final String DEFAULT_MIME = "image/jpeg";
private static final String SELECTOR_QUALITY_KEY = "quality";
private static final String SELECTOR_WIDTH_KEY = "width";
Expand All @@ -134,6 +138,10 @@ public AdaptiveImageServlet(MimeTypeService mimeTypeService, AssetStore assetSto
this.metrics = metrics;
this.defaultResizeWidth = defaultResizeWidth > 0 ? defaultResizeWidth : DEFAULT_RESIZE_WIDTH;
this.maxInputWidth = maxInputWidth > 0 ? maxInputWidth : DEFAULT_MAX_SIZE;

if (!AVOID_USAGE_LOGGER.isWarnEnabled()) {
LOGGER.info("Warnings for the use of the AdaptiveImageServlet disabled");
}
}

@Override
Expand Down Expand Up @@ -280,6 +288,8 @@ protected void transformAndStreamAsset(SlingHttpServletResponse response, ValueM
boolean flipHorizontally = componentProperties.get(Image.PN_FLIP_HORIZONTAL, Boolean.FALSE);
boolean flipVertically = componentProperties.get(Image.PN_FLIP_VERTICAL, Boolean.FALSE);
if (rotationAngle != 0 || rectangle != null || resizeWidth > 0 || flipHorizontally || flipVertically) {

logUsageWarning();
int originalWidth = getDimension(asset.getMetadataValue(DamConstants.TIFF_IMAGEWIDTH));
int originalHeight = getDimension(asset.getMetadataValue(DamConstants.TIFF_IMAGELENGTH));
Layer layer = null;
Expand Down Expand Up @@ -412,6 +422,7 @@ private void transformAndStreamFile(SlingHttpServletResponse response, ValueMap
boolean flipVertically = componentProperties.get(Image.PN_FLIP_VERTICAL, Boolean.FALSE);
if (is != null) {
if (rotationAngle != 0 || rectangle != null || resizeWidth > 0 || flipHorizontally || flipVertically) {
logUsageWarning();
Layer layer = new Layer(is);
if (rectangle != null) {
layer.crop(rectangle);
Expand Down Expand Up @@ -1001,6 +1012,12 @@ private int getResizeWidth(@NotNull Resource imageResource, @NotNull SlingHttpSe
}
return allowedResizeWidth;
}

private void logUsageWarning() {
AVOID_USAGE_LOGGER.warn("An image is transformed on-the-fly, which can be a very resource intensive operation. "
+ "If done frequently, you should consider switching to dynamic AEM web-optimized images "
+ "or creating such a rendition upfront using processing profiles.");
}



Expand Down

0 comments on commit 117ef36

Please sign in to comment.