Skip to main content
TheBigRed
Level 4
Oct 16, 2015 2:27 AM UTC
Solved

Asset preview in Touch UI

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Oct 16, 2015 2:27 AM UTC

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

7 replies

smacdonald2008
smacdonald2008Accepted solution
Level 10
Oct 16, 2015 2:27 AM UTC

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

Translate
TheBigRed
TheBigRedAuthor
Level 4
Oct 16, 2015 2:27 AM UTC

Hey any update on this?

Thanks

Translate
smacdonald2008
Level 10
Oct 16, 2015 2:27 AM UTC

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

Translate
TheBigRed
TheBigRedAuthor
Level 4
Oct 16, 2015 2:27 AM UTC

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

Translate
smacdonald2008
Level 10
Oct 16, 2015 2:27 AM UTC

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

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. 

Translate
TheBigRed
TheBigRedAuthor
Level 4
Oct 16, 2015 2:27 AM UTC

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

Translate
smacdonald2008
Level 10
Oct 16, 2015 2:27 AM UTC

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

Translate