Expand my Community achievements bar.

SOLVED

Asset preview in Touch UI

Avatar

Level 5

What is the script that I can extend off when AEM makes a asset preview sort of like a folder thumbnail?

Since a preview is not set for certain mime types, particularly XML for my case, I would like to create

a preview when an XML asset is uploaded to the DAM. I'm guessing creating a custom Media Handler?

 

Thanks,

Ram

1 Accepted Solution

Avatar

Correct answer by
Level 10
7 Replies

Avatar

Level 10

Work with this API: com.day.cq.dam.commons.handler.AbstractAssetHandler

We have a community article that will get you up and running with the AbstractAssetHandler API: https://helpx.adobe.com/experience-manager/using/damhandler.html

Avatar

Level 5

The method the article uses is deprecated and says use AssetHandler.getImage(Rendition rendition).

If I pass the original file will this generate a thumbnail image for me AND apply it to the asset?

How does an thumbnail image get picked up by AEM? Is there a specific dimension it looks for?

 

Thanks

Avatar

Level 10

This article shows you how to get up and running with the AbstractAssetHandler API.  It uses this API to handle the asset and retrieve the number of words in a text doc. But once you know how to use this API - you can use it to address your use case. 

http://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/day/cq/dam/commons/handler/AbstractAssetHandler.h...

We will update this article to not use a dep method. 

"How does AEM pick up the thumbnail image"

Create application logic in your service to do what you want with it. Just because you convert an asset to a thumbnail - your service is still responsible for what it does with the asset. Maybe you want to place it in a specific DAM folder (for example) and then kick off a workflow that uses the thumbnail version of the asset. 

Avatar

Level 5

Regarding the community article given, and the new method (AssetHandler.getImage(Rendition rendition)) that the API suggests instead of the deprecated one:

I'm getting a nulllpointer exception associated with the new method and a blank white thumbnail. What API can I use to layer text to an image and return it as a bufferedImage according

to the AssetHandler API.

Here is my code:

     public BufferedImage getImage(Rendition ren) {

         final String text = "TEST";
         final Layer layer = new Layer(500, 600, Color.WHITE);
         layer.setPaint(Color.black);
         Font font = new Font("Arial", 12);
         String displayText = this.getDisplayText(text, 600, 12);
         
         if (displayText != null && displayText.length() > 0)
         { // commons-gfx Font class would throw IllegalArgumentException on empty or null text layer.drawText(10, 10, 500, 600, displayText, font, Font.ALIGN_LEFT, 0, 0); }
             // create watermark and merge with text layer
              
             Layer watermarkLayer;
             try
             {
              final Session session = node2.getSession();
              watermarkLayer = ImageHelper.createLayer(session, "/content/dam/geometrixx/icons/certificate.png");
              watermarkLayer.setX(MARGIN); watermarkLayer.setY(MARGIN);
              layer.merge(watermarkLayer);
             }
             catch (Exception e)
             {
                 e.printStackTrace();
             }
         
        }
         layer.crop(new Rectangle(510, 600));
         return layer.getImage();
         
     }

 

In addition the following code:

        extractedMetadata.setProperty("Title", "Text File");
        extractedMetadata.setProperty("text", text);

Where can I see these properties in CRDXE?

 

Thanks

Avatar

Level 10

I will look into this code on mon. IN meanwhile - if another community has a good code example - please post. 

Avatar

Correct answer by
Level 10

Instead of using 

com.day.cq.wcm.foundation.ImageHelper

Use this API: 

com.day.cq.commons.ImageHelper

The article will be updated to use this API to get a Layer object. 

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/day/image/Layer.html