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

ASSETS-44583 : Add Image modifier support in site editor page #2887

Open
wants to merge 2 commits 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class ImageImplTest extends com.adobe.cq.wcm.core.components.internal.models.v2.
private static final String PAGE3_IMAGE0_PATH = PAGE3 + "/jcr:content/root/page3_image0";
private static final String NGDM_IMAGE1_PATH = "/content/ngdm_test_page/jcr:content/root/ngdm_test_page_image1";
private static final String NGDM_SMARTCROP_IMAGE_PATH = "/content/ngdm_test_page/jcr:content/root/ngdm_test_page_smartcrop_image";

private static final String NGDM_MODIFIERS_IMAGE_PATH = "/content/ngdm_test_page/jcr:content/root/ngdm_test_page_modifiers_image";
private static final String NGDM_SMARTCROP_AUTO_IMAGE_PATH = "/content/ngdm_test_page/jcr:content/root/ngdm_test_page_smartcrop_image_auto";


Expand Down Expand Up @@ -731,6 +733,19 @@ void testNgdmImageWithSmartCropRendition() {
Utils.testJSONExport(image, Utils.getTestExporterJSONPath(testBase, NGDM_SMARTCROP_IMAGE_PATH));
}

@Test
void testNgdmImageWithModifiers() {
MockNextGenDynamicMediaConfig config = new MockNextGenDynamicMediaConfig();
config.setEnabled(true);
config.setRepositoryId("testrepo");
config.setAssetMetadataPath("/adobe/assets/{asset-id}/metadata");
context.registerInjectActivateService(config);

Image image = getImageUnderTest(NGDM_MODIFIERS_IMAGE_PATH);
Utils.testJSONExport(image, Utils.getTestExporterJSONPath(testBase, NGDM_MODIFIERS_IMAGE_PATH));
assertTrue(image.getSrc().contains("&width=100&height=200"));
}

@Test
void testNgdmImageWithAutoSmartCropRendition() throws Exception {
String expectedMetadataAPIResponseJSON = "{\"assetId\":\"urn:aaid:aem:33b6255d-a978-43ad-8e2e-ef5677c64715\",\"repositoryMetadata\":{\"smartcrops\":{\"Large\":{\"height\":\"1200\",\"left\":\"0.0\",\"manualCrop\":\"false\",\"width\":\"800\",\"top\":\"0.16\"},\"Medium\":{\"height\":\"800\",\"left\":\"0.0\",\"manualCrop\":\"false\",\"width\":\"600\",\"top\":\"0.0\"}}}}";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"id": "image-06acc3dd21",
"src": "https://testrepo/adobe/dynamicmedia/deliver/urn:aaid:aem:e82c3c87-1453-48f5-844b-1822fb610911/cutfruits.png?width=640&preferwebp=true&width=100&height=200",
"lazyEnabled": true,
"sizes": "",
"dataLayer": {
"image-06acc3dd21": {
"@type": "core/wcm/components/image/v3/image"
}
},
":type": "core/wcm/components/image/v3/image"
}
7 changes: 7 additions & 0 deletions bundles/core/src/test/resources/image/v3/test-content.json
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,13 @@
"fileReference": "/urn:aaid:aem:e82c3c87-1453-48f5-844b-1822fb610911/cutfruits.png",
"smartCropRendition": "Medium"
},
"ngdm_test_page_modifiers_image": {
"jcr:primaryType": "nt:unstructured",
"jcr:createdBy": "admin",
"sling:resourceType": "core/wcm/components/image/v3/image",
"fileReference": "/urn:aaid:aem:e82c3c87-1453-48f5-844b-1822fb610911/cutfruits.png",
"imageModifiers": "&width=100&height=200"
},
"ngdm_test_page_smartcrop_image_auto": {
"jcr:primaryType": "nt:unstructured",
"jcr:createdBy": "admin",
Expand Down
Loading