I have a requirement where I need to create a custom rendition for the images in the AEM DAM that has already being uploaded in the DAM and store those custom renditions in the same path of the image in the DAM programmatically using java in aem6.3.
Any idea/approach to proceed as solution to the above questions?
Solved! Go to Solution.
Hi,
I would suggest create a workflow process and make use of this RenditionMaker api and Assethandler Api to create our own renditions for a particular image asset.
Kindly check out this code. It would be much helpful.
@Properties({
@Property(name = "process.label", value = "Custom Image Rendition Process") })
@Component
@Service
public class CustomImageRendition implements WorkflowProcess {
private static final Logger logger = Logger.getLogger(CustomImageRendition.class.getName());
@Reference
protected ResourceResolverFactory resourceResolverFactory;
@Reference
RenditionMaker renditionMaker;
@Reference
AssetHandler assetHandler;
ResourceResolver resourceResolver;
@Override
public void execute(WorkItem workItem, WorkflowSession session, MetaDataMap args) throws WorkflowException {
try
{
String assetPath = null;
// Get the resource resolver using system user and user mapper service
Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "getResourceResolver");
resourceResolver = resourceResolverFactory.getServiceResourceResolver(param);
String payloadString = workItem.getWorkflowData().getPayload().toString();
logger.info("payload path"+payloadString);
// convert the payload path into a Resource
Resource damResource = resourceResolver.resolve(payloadString);
if (damResource != null){
logger.info("the damResource is exists .. "+damResource);
// further convert the resource into Dam asset
Asset damAsset = damResource.adaptTo(Asset.class);
if(damAsset !=null)
{
logger.info("dam asset exists .. "+ damAsset);
// create a Rendition Template using Rendition Maker Api and give the width, height, quality, mimietype for your template
int width = 250;
int height = 250;
int quality = 100;
String mimeType = "image/jpeg";
String[] mimeTypesToKeep ={ "image/jpeg","image/png"};
RenditionTemplate renditionTemplate = renditionMaker.createWebRenditionTemplate(damAsset, width, height, quality,
mimeType,mimeTypesToKeep);
// Using the rendition template created above , generate the renditions
List<Rendition> renditionList = renditionMaker.generateRenditions(damAsset, renditionTemplate);
// using Asset Handler Api create thumbnails using the rendition for the asset.
Collection<ThumbnailConfig> configs = null;
for(Rendition rendition : renditionList ){
assetHandler.createThumbnails( damAsset, rendition, configs);
}
// Just to check if our rendition got added.
for (Rendition rendition2 : damAsset.getRenditions()) {
logger.info(rendition2.getName() + " " + rendition2.getPath()+"\n");
}
resourceResolver.commit();
}
}
}
catch(LoginException |IOException e){
e.printStackTrace();
}
}
}
You can create a launcher to make this workflow process to run. Hope this might help.
Thanks and regards
Abinaya
you can use RenditionMaker com.day.cq.dam.api.renditions.RenditionMaker
Why are you not adding these renditions to the workflow launcher ?
I need to create custom renditions when the DAM update asset workflow is triggered i.e; when the image is uploaded into the DAM (something like custom workflow step in the above workflow process) programmatically..Can you pl help me how to access the above workflow and include the custom step to add custom rendition for the image uploaded in the DAM?
Views
Replies
Total Likes
Hi Malar
I don't know if this is what you are looking for. If the requirement is only to generate a custom rendition when user uploads an image , then you don't need to write any custom code for that as there is already a workflow available which handles the same.
You can go to workflow manager and DAM Update Asset workflow ; /etc/workflow/models/dam/update_asset.html
Double click "Process Thumbnails" step
Add your Custom rendition in requested format in the below field .
Once set, save your workflow and upload a new image Check the renditions below the uploaded asset and you shud see your new rendition
I have not set it , below image is just for reference to mention that the new rendition will be available in this format.
Hope this is exactly what you are looking for . Happy Friday
Hi Veena,
I have created custom Audio Component in Asset share commons in AEM ,everything is working fine except i am not able to get the thumbnail in audio file(.mp3 and. wav).I have done some R&D then I found that Audio files does not have any rendition except original one.So my requirement is that is there anyway that we can add thumbnail in audio file.
PFB Screenshot of .mp3 node in crx.
see in above picture there is no rendition except original one that's why it is coming as without thumbnail,When I copy any image and paste it here(manually) then thumbnail is appear in audio files.
but i don't want to do it manually this thing,Can you please suggest some way how can I solve this issue.It will be very helpful for me.
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Thanks Veena!!
The above solution gave an understanding, but my requirement is to add custom rendition once the image is uploaded in dam the dam update asset workflow should include the custom rendition image. This should be done programmatically in java(to update the workflow process).
Views
Replies
Total Likes
Hi Malar,
Veena's method is accurate and is the best approach. The rendition is created by java process used by one of the process step. You can replace this java process with your own classes.
I am bit fuzzy what you exactly need. If you want to duplicate this process from scratch then do the following:
- Disable the existing OOTB create and update via workflow launcher window and then create your own workflow model by copying the following model.
/etc/workflow/models/dam/update_asset.html
- You can add step programatically in your custom workflow model. The step could use your own Java process to create the rendition.
- AEM uses imagemagick API to create renditions. You could use the same API or use your own.
- You can trigger the workflow either by workflow launcher or by adding a listener.
Hope this helps
Malar,
Same as uagnihotri , I am not sure what your exact requirement is .
If you can give me the exact requirement you are trying to achieve may be I can give you a better solution
Thanks
Veena
To answer your question in reply (highlighted) , dam update asset workflow is the one who creates the renditions when you upload any DAM asset. So if you follow the above steps, as soon as you upload the image , it will take care of the rendition creation.
Why don't you do a POC and confirm if this is not what exactly you are looking for ? Once POC is done you will have an idea on exactly what you need .
Hi,
I would suggest create a workflow process and make use of this RenditionMaker api and Assethandler Api to create our own renditions for a particular image asset.
Kindly check out this code. It would be much helpful.
@Properties({
@Property(name = "process.label", value = "Custom Image Rendition Process") })
@Component
@Service
public class CustomImageRendition implements WorkflowProcess {
private static final Logger logger = Logger.getLogger(CustomImageRendition.class.getName());
@Reference
protected ResourceResolverFactory resourceResolverFactory;
@Reference
RenditionMaker renditionMaker;
@Reference
AssetHandler assetHandler;
ResourceResolver resourceResolver;
@Override
public void execute(WorkItem workItem, WorkflowSession session, MetaDataMap args) throws WorkflowException {
try
{
String assetPath = null;
// Get the resource resolver using system user and user mapper service
Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "getResourceResolver");
resourceResolver = resourceResolverFactory.getServiceResourceResolver(param);
String payloadString = workItem.getWorkflowData().getPayload().toString();
logger.info("payload path"+payloadString);
// convert the payload path into a Resource
Resource damResource = resourceResolver.resolve(payloadString);
if (damResource != null){
logger.info("the damResource is exists .. "+damResource);
// further convert the resource into Dam asset
Asset damAsset = damResource.adaptTo(Asset.class);
if(damAsset !=null)
{
logger.info("dam asset exists .. "+ damAsset);
// create a Rendition Template using Rendition Maker Api and give the width, height, quality, mimietype for your template
int width = 250;
int height = 250;
int quality = 100;
String mimeType = "image/jpeg";
String[] mimeTypesToKeep ={ "image/jpeg","image/png"};
RenditionTemplate renditionTemplate = renditionMaker.createWebRenditionTemplate(damAsset, width, height, quality,
mimeType,mimeTypesToKeep);
// Using the rendition template created above , generate the renditions
List<Rendition> renditionList = renditionMaker.generateRenditions(damAsset, renditionTemplate);
// using Asset Handler Api create thumbnails using the rendition for the asset.
Collection<ThumbnailConfig> configs = null;
for(Rendition rendition : renditionList ){
assetHandler.createThumbnails( damAsset, rendition, configs);
}
// Just to check if our rendition got added.
for (Rendition rendition2 : damAsset.getRenditions()) {
logger.info(rendition2.getName() + " " + rendition2.getPath()+"\n");
}
resourceResolver.commit();
}
}
}
catch(LoginException |IOException e){
e.printStackTrace();
}
}
}
You can create a launcher to make this workflow process to run. Hope this might help.
Thanks and regards
Abinaya
Hi @abinayaSirius ,
Is it possible to create a custom rendition for mixedmedia sets using this method? I tried this but rendition list was null. Do you know if there's any other way to generate the renditions for sets?
Thank you.
Views
Replies
Total Likes
Hi Veena,
Is there any option to rename the renditions created using OOTB workflow , for Ex: cq5dam.thumbnail.100.150.png to mobile.png ..?
Views
Replies
Total Likes
@VeenaVikraman if the requirement is to create a rendition, only to a particular sub folder images, and all other default renditions to all images across the dam, do you have any insights on how should we solution it?
In this case, can we use the same dam update workflow with a new OOB process thumbnail step(but is it possible to add a branching for just a folder here with OOB steps)? Or it should be a custom process step to generate rendition programmatically wherein from the code we can check for folder path as well.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies