Height and Width of the Rendition of the Image in Java | Community
Skip to main content
tc94524330
Level 3
July 12, 2016
Solved

Height and Width of the Rendition of the Image in Java

  • July 12, 2016
  • 2 replies
  • 4974 views

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    

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by leeasling

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; }

2 replies

leeaslingAccepted solution
Level 8
July 12, 2016

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; }
kautuk_sahni
Community Manager
Community Manager
July 13, 2016

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