Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

AEM Cloud Service - Dynamic Media Process New Smart Crops | AEM Community Blog Seeding

Avatar

Administrator

BlogImage.jpg

AEM Cloud Service - Dynamic Media Process New Smart Crops by Sreekanth Choudry Nalabotu

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

AEM Cloud Service - Dynamic Media Process New Smart Crops

Q&A

Please use this thread to ask the related questions.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

0 Replies

The ultimate experience is back.

Join us in Vegas to build skills, learn from the world's top brands, and be inspired.

Register Now