Skip to content

Commit

Permalink
ASSETS-44583 : Add Image modifier support in site editor page
Browse files Browse the repository at this point in the history
  • Loading branch information
igurjar committed Nov 27, 2024
1 parent 77dd95c commit 626f0d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ private void initNextGenerationDynamicMedia() {
properties = resource.getValueMap();
String fileReference = properties.get("fileReference", String.class);
String smartCrop = properties.get("smartCropRendition", String.class);
String modifiers = properties.get("imageModifiers", String.class);
if (isNgdmImageReference(fileReference)) {
int width = currentStyle.get(PN_DESIGN_RESIZE_WIDTH, DEFAULT_NGDM_ASSET_WIDTH);
NextGenDMImageURIBuilder builder = new NextGenDMImageURIBuilder(nextGenDynamicMediaConfig, fileReference)
Expand All @@ -339,6 +340,9 @@ private void initNextGenerationDynamicMedia() {
if(StringUtils.isNotEmpty(smartCrop) && !StringUtils.equals(smartCrop, SMART_CROP_AUTO)) {
builder.withSmartCrop(smartCrop);
}
if (StringUtils.isNotEmpty(modifiers)) {
builder.withImageModifiers(modifiers);
}
src = builder.build();
ngdmImage = true;
hasContent = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class NextGenDMImageURIBuilder {
private int height;
private boolean preferWebp = true;

private String modifiers;

public NextGenDMImageURIBuilder(NextGenDynamicMediaConfig config, String fileReference) {
this.config = config;
this.fileReference = fileReference;
Expand Down Expand Up @@ -84,6 +86,15 @@ public NextGenDMImageURIBuilder withPreferWebp(boolean preferWebp) {
return this;
}

/**
* Set extra image modifiers.
* @param modifiersStr
*/
public NextGenDMImageURIBuilder withImageModifiers(String modifiersStr) {
this.modifiers = modifiersStr;
return this;
}

/**
* Use this to create a NextGen Dynamic Media Image URI.
* @return a uri.
Expand Down Expand Up @@ -124,6 +135,13 @@ public String build() {
}
uriBuilder.deleteCharAt(uriBuilder.length() - 1);
}
if(StringUtils.isNotEmpty(this.modifiers)) {
if (this.modifiers.startsWith("&")) {
uriBuilder.append(this.modifiers);
} else {
uriBuilder.append("&" + this.modifiers);
}
}
return uriBuilder.toString();
}
LOGGER.info("Invalid fileReference or NGDMConfig. fileReference = {}", this.fileReference);
Expand Down

0 comments on commit 626f0d5

Please sign in to comment.