Abstract
Goal
AEM Cloud Version : 2021.2.4944.20210221T230729Z-210225 (Feb 21, 2021)
When new smart crop settings are added in Image Profile, assets have to be reprocessed to see the new crops (otherwise they show unprocessed). However reprocessing results in generating all crops again, so any manual adjustments made to the previous crops by creatives get overwritten. This post explains how to preserve the manually adjusted smart crops, and generate new unprocessed ones...for scene7 api check this documentation
Solution
1) Add a datasource to read the existing smart crops /apps/eaem-cs-process-new-smart-crops/extensions/smart-crop-renditions
<%@include file="/libs/granite/ui/global.jsp"%>
<%@page session="false"
import="java.util.Iterator,
org.apache.sling.commons.json.JSONObject,
com.adobe.granite.ui.components.Tag"%>
<%@ page import="com.adobe.granite.ui.components.ds.DataSource" %>
<%@ page import="org.apache.sling.commons.json.JSONArray" %>
<%@ page import="apps.experienceaem.assets.core.services.DMCService" %>
<%
ValueMap dynVM = null;
JSONObject dynRenditions = new JSONObject();
Resource dynResource = null;
DMCService dmcService = sling.getService(DMCService.class);
response.setContentType("application/json");
DataSource rendsDS = null;
try{
rendsDS = cmp.getItemDataSource();
}catch(Exception e){
//could be pixel crop, ignore...
}
if(rendsDS == null){
dynRenditions.write(response.getWriter());
return;
}
for (Iterator items = rendsDS.iterator(); items.hasNext();) {
JSONObject dynRendition = new JSONObject();
dynResource = items.next();
dynVM = dynResource.getValueMap();
String name = String.valueOf(dynVM.get("breakpoint-name"));
dynRendition.put("name", name);
dynRendition.put("cropdata", getCropData(dynVM));
dynRenditions.put(name, dynRendition);
}
dynRenditions.write(response.getWriter());
%>
<%!
private static JSONArray getCropData(ValueMap dynVM) throws Exception{
JSONArray cropArray = new JSONArray();
JSONObject cropData = new JSONObject();
cropData.put("name", String.valueOf(dynVM.get("breakpoint-name")));
cropData.put("id", dynVM.get("id"));
cropData.put("topN", dynVM.get("topN"));
cropData.put("bottomN", dynVM.get("bottomN"));
cropData.put("leftN", dynVM.get("leftN"));
cropData.put("rightN", dynVM.get("rightN"));
cropArray.put(cropData);
return cropArray;
}
%>
2) To get the smart crops as json send the asset path as resource suffix to data source eg. https://author-pxxxxx-exxxxx.adobeaemcloud.com/apps/eaem-cs-process-new-smart-crops/extensions/smart-crop-renditions/renditions.html/content/dam/experience-aem/am-i-doing-this-right.png
Read Full Blog
Q&A
Please use this thread to ask the related questions.
Kautuk Sahni