Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2490 log usage warning in AdaptiveImageServlet #2492

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added bundles/core/jacoco.exec
Binary file not shown.
Original file line number Diff line number Diff line change
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