Expand my Community achievements bar.

SOLVED

Crop an Image programatically in AEM

Avatar

Level 2

Hi

  I am trying to crop an image programatically

 

Resource res = resourceResolver.getResource("/content/dam/images/test.jpg");
Asset asst = res.adaptTo(Asset.class);
Resource dataResource = resourceResolver.getResource(res.getPath()+"/jcr:content/renditions/original/jcr:content");
Layer layer = ImageHelper.createLayer(currentNode.getSession(),asst.getCurrentOriginal().getPath());
log.error("LAYER**" + layer);
Rectangle rect = ImageHelper.getCropRect("0,0,100,100",res.getPath());
layer.crop(rect);

 

  But I am not able to do the same since I am getting null pointer exception , since the layer itself is null. Can I know where I am making a mistake

 

Thanks

Veena

1 Accepted Solution

Avatar

Correct answer by
Employee

can you post the exact stack trace...  the blog post uses ImageHelper.createLayer(dataResource)

asset.getCurrentOriginal() is deprecated - https://docs.adobe.com/docs/en/aem/6-0/develop/ref/javadoc/com/day/cq/dam/api/Asset.html#getCurrentO...()

 

Deprecated. Will be removed without replacement. The concept of current originals will henceforth be managed through versioning the asset upon modifying the original. Use getOriginal()instead.

 

Returns the Rendition representing the asset's rendition currently marked as the asset's unmodified, original version. A rendition is marked as the original of an asset via the existence of the propertycurrentOriginal on the asset's content node. The property contains the path of the rendition to be considered the original. E.g. /content/dam/geometrixx/banners/banner-mono.png/jcr:content/currentOriginal with value /content/dam/geometrixx/banners/banner-mono.png/jcr:content/renditions/myOriginal.

View solution in original post

6 Replies

Avatar

Level 10

Also, just verify if you are importing a right 'Layer' package. 

Avatar

Level 2

Hi Scott,

   I followed the same article , but I am getting Null for  

Layer layer = ImageHelper.createLayer(currentNode.getSession(),asst.getCurrentOriginal().getPath());

Avatar

Level 2

Hi Bsloki

   I am using com.day.image.Layer 

Avatar

Level 10

Hi Veena,

 Can you please debug or put sysout and check which exactly is coming as null.

It might be ImageHelper, Session or the path

Avatar

Correct answer by
Employee

can you post the exact stack trace...  the blog post uses ImageHelper.createLayer(dataResource)

asset.getCurrentOriginal() is deprecated - https://docs.adobe.com/docs/en/aem/6-0/develop/ref/javadoc/com/day/cq/dam/api/Asset.html#getCurrentO...()

 

Deprecated. Will be removed without replacement. The concept of current originals will henceforth be managed through versioning the asset upon modifying the original. Use getOriginal()instead.

 

Returns the Rendition representing the asset's rendition currently marked as the asset's unmodified, original version. A rendition is marked as the original of an asset via the existence of the propertycurrentOriginal on the asset's content node. The property contains the path of the rendition to be considered the original. E.g. /content/dam/geometrixx/banners/banner-mono.png/jcr:content/currentOriginal with value /content/dam/geometrixx/banners/banner-mono.png/jcr:content/renditions/myOriginal.