Crop an Image programatically in AEM | Community
Skip to main content
Level 2
October 16, 2015
Solved

Crop an Image programatically in AEM

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
sreekncAccepted solution
Employee
October 16, 2015

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#getCurrentOriginal()

 

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.

6 replies

Lokesh_Shivalingaiah
Level 10
October 16, 2015

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

Translate
smacdonald2008
Level 10
October 16, 2015

See this community article - it talks about using this API:

http://experience-aem.blogspot.ca/2014/01/aem-cq-56-crop-images-in-workflow-step.html

Hope this helps. 

Translate
Level 2
October 16, 2015

Hi Scott,

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

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

Translate
Level 2
October 16, 2015

Hi Bsloki

   I am using com.day.image.Layer 

Translate
Lokesh_Shivalingaiah
Level 10
October 16, 2015

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

Translate
sreekncAccepted solution
Employee
October 16, 2015

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#getCurrentOriginal()

 

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