Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Height and Width of the Rendition of the Image in Java

Avatar

Level 4

Hi,

I am working a lot recently with Assets. I want to get dimensions of the image renditions for the image. I can get the size of the rendition using getSize() method but was not able to find any method to get dimensions or say length and width of the image. 

I can get the length and width of the original image from metadata tiff:ImageLength and tiff:ImageWidth but i am not seeing any information like this for renditions. 

Can anyone provide any suggestions on hoe to get dimensions of the renditions.

 

Thanks    

1 Accepted Solution

Avatar

Correct answer by
Level 8

Try this

public int getWidth() { Asset asset = this.getResourceResolver().getResource("imagepath").adaptTo(Asset.class); Rendition rendition = asset.getRendition("cq5dam.thumbnail.48.48.png"); try { BufferedImage bimg = ImageIO.read(rendition.getStream()); return bimg.getWidth(); } catch (Exception e) { } return 0; }

View solution in original post

2 Replies

Avatar

Correct answer by
Level 8

Try this

public int getWidth() { Asset asset = this.getResourceResolver().getResource("imagepath").adaptTo(Asset.class); Rendition rendition = asset.getRendition("cq5dam.thumbnail.48.48.png"); try { BufferedImage bimg = ImageIO.read(rendition.getStream()); return bimg.getWidth(); } catch (Exception e) { } return 0; }

Avatar

Administrator

Hi 

You can also try, the AssetDetails class to get the details of a particular DAM Asset.

For e.g.,

Resource res = resourceResolver.getResource("<<path to resource>>"); 
AssetDetails assetDetails = new AssetDetails(res);
assetDetails.getHeight();
assetDetails.getWidth();

 

Some more reference links:- 

https://forums.adobe.com/thread/1065593

https://docs.adobe.com/docs/en/aem/6-0/develop/ref/javadoc/com/day/cq/commons/ImageResource.html

https://docs.adobe.com/docs/en/aem/6-0/develop/ref/javadoc/com/day/cq/dam/commons/util/DamUtil.html

http://cq5cms.blogspot.in/2014/07/render-image-rendtions-dynamically-in.html

http://cq5cms.blogspot.in/2014/07/renders-image-dynamically-in-cq5.html

 

I hope this will help you.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni