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
BedrockMission!

Learn More

View all

Sign in to view all badges

How to create a custom rendition to the images in the AEM DAM programatically using java in AEM6.3?

Avatar

Avatar
Validate 1
Level 2
Malarvizhi_Sara
Level 2

Likes

5 likes

Total Posts

15 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
View profile

Avatar
Validate 1
Level 2
Malarvizhi_Sara
Level 2

Likes

5 likes

Total Posts

15 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
View profile
Malarvizhi_Sara
Level 2

16-03-2018

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?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 1
Level 1
abinayaSirius
Level 1

Likes

2 likes

Total Posts

2 posts

Correct Reply

1 solution
Top badges earned
Boost 1
Affirm 1
View profile

Avatar
Boost 1
Level 1
abinayaSirius
Level 1

Likes

2 likes

Total Posts

2 posts

Correct Reply

1 solution
Top badges earned
Boost 1
Affirm 1
View profile
abinayaSirius
Level 1

30-03-2018

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

Answers (9)

Answers (9)

Avatar

Avatar
Validate 1
Level 2
uagnihotri
Level 2

Likes

7 likes

Total Posts

23 posts

Correct Reply

3 solutions
Top badges earned
Validate 1
Give Back
Boost 5
Boost 3
Boost 1
View profile

Avatar
Validate 1
Level 2
uagnihotri
Level 2

Likes

7 likes

Total Posts

23 posts

Correct Reply

3 solutions
Top badges earned
Validate 1
Give Back
Boost 5
Boost 3
Boost 1
View profile
uagnihotri
Level 2

19-03-2018

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

Avatar

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

471 likes

Total Posts

1,039 posts

Correct Reply

121 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

471 likes

Total Posts

1,039 posts

Correct Reply

121 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile
Veena_Vikram
MVP

16-03-2018

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

1443706_pastedImage_5.png

Double click "Process Thumbnails" step

1443911_pastedImage_6.png

Add your Custom rendition in requested format in the below field .

1443920_pastedImage_8.png

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.

1443913_pastedImage_7.png

Hope this is exactly what you are looking for . Happy Friday

Avatar

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

471 likes

Total Posts

1,039 posts

Correct Reply

121 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

471 likes

Total Posts

1,039 posts

Correct Reply

121 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile
Veena_Vikram
MVP

21-03-2018

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 .

Avatar

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

471 likes

Total Posts

1,039 posts

Correct Reply

121 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

471 likes

Total Posts

1,039 posts

Correct Reply

121 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile
Veena_Vikram
MVP

21-03-2018

Malar,

     Same as uagnihotri , I am not sure what your exact requirement is .

  • If you requirement is creating a custom rendition for any asset uploaded . let's say you need all your assets to have 80:100 rendition , then if you add this in above workflow , as soon as an asset is uploaded to DAM , the event listener will listen the upload and trigger the workflow Launcher which will run the DAM Update Asset workflow

  • But if your requirement is something like , each asset should be created using different rendition , which you decide on run-time , then you should follow uagnihotri recommendations and create your own custom process step and attach it to the above workflow (which I won't recommend) or create a new workflow and launcher to listen to your DAM asset .

If you can give me the exact requirement you are trying to achieve may be I can give you a better solution

Thanks

Veena

Avatar

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

471 likes

Total Posts

1,039 posts

Correct Reply

121 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

471 likes

Total Posts

1,039 posts

Correct Reply

121 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile
Veena_Vikram
MVP

16-03-2018

Why are you not adding these renditions to the workflow launcher ?

Avatar

Avatar
Validate 1
Level 4
Rima_Mittal
Level 4

Likes

30 likes

Total Posts

82 posts

Correct Reply

17 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
Rima_Mittal
Level 4

Likes

30 likes

Total Posts

82 posts

Correct Reply

17 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
Rima_Mittal
Level 4

16-03-2018

Avatar

Avatar
Level 1
venkateshvemula
Level 1

Likes

0 likes

Total Posts

1 post

Correct Reply

0 solutions
View profile

Avatar
Level 1
venkateshvemula
Level 1

Likes

0 likes

Total Posts

1 post

Correct Reply

0 solutions
View profile
venkateshvemula
Level 1

13-08-2019

Hi Veena,

     Is there any option to rename the renditions created using OOTB workflow , for Ex: cq5dam.thumbnail.100.150.png to mobile.png ..?

Avatar

Avatar
Validate 1
Level 2
Malarvizhi_Sara
Level 2

Likes

5 likes

Total Posts

15 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
View profile

Avatar
Validate 1
Level 2
Malarvizhi_Sara
Level 2

Likes

5 likes

Total Posts

15 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
View profile
Malarvizhi_Sara
Level 2

19-03-2018

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).

Avatar

Avatar
Validate 1
Level 2
Malarvizhi_Sara
Level 2

Likes

5 likes

Total Posts

15 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
View profile

Avatar
Validate 1
Level 2
Malarvizhi_Sara
Level 2

Likes

5 likes

Total Posts

15 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
View profile
Malarvizhi_Sara
Level 2

16-03-2018

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?