I have a scenario where I have to read each of the manually added renditions height and width.
Rendition rendition = resource.adaptTo(Rendition.class);// rendition obj would only give size of the rendition (rendition.getSize()) not height and width.
For generated renditions, we would at least read it from the node name (String Operations) (cq5dam.thumbnail.140.100.png).
But how to get the height and width of the renditions which are other than ootb renditions and doesnt have height and width values in the filename.
for ex: cq5dam.fpo.jpeg
Views
Replies
Total Likes
Hi @mrudul
You can try the Asset class to get the details of a particular DAM Asset.
e.g.
Image Width
public int getWidth() {
Asset asset = resourceResolver.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;
}
Image Height
public int getWidth() {
Asset asset = resourceResolver.getResource("imagepath").adaptTo(Asset.class);
Rendition rendition = asset.getRendition("cq5dam.thumbnail.48.48.png");
try {
BufferedImage bimg = ImageIO.read(rendition.getStream());
return bimg.getHeight();
} catch (Exception e) {
}
return 0;
}
Hope that helps!
Regards,
Santosh
@SantoshSai : Thanks for your time.
I tried this but no luck. This is what I added to my class. and getting Exception as below.
Just to cross check i am using below imports
BufferedImage bimg; bimg = ImageIO.read(rendition.getStream()); width = bimg.getWidth(); height = bimg.getHeight();
From the initial screenshot, u can see the properties of a particular resource I am trying to access.
@SantoshSai : Can you please check this once. ?
@mrudul
Imports looks correct, can you check in parameter(image rendition) passing
Rendition rendition = asset.getRendition("cq5dam.thumbnail.48.48.png");
is exists in repo?
import javax.imageio.ImageIO;
import com.adobe.granite.asset.api.Asset;
import com.adobe.granite.asset.api.Rendition;
import java.awt.image.BufferedImage;
public int getWidth() { Asset asset = resourceResolver.getResource("/content/dam/we-retail/en/features/cart.png").adaptTo(Asset.class); Rendition rendition = asset.getRendition("cq5dam.thumbnail.48.48.png"); try { BufferedImage bimg = ImageIO.read(rendition.getStream()); return bimg.getHeight(); } catch (Exception e) { } return 0; }
It returns the width as expected.
HI @mrudul
The rendition is also an asset and you can get the length and width using the metadata.
Int length = resourceResolver.getResource("<<path to resource>>").adapto(Asset.class).getMetadataValue(tiff:ImageLength)
Hope this helps!
Thanks,
Kiran Vedantam.
Hi @Kiran_Vedantam
metadata will only be generated for the original uploaded asset, there will be no metadata for generated rendition images
If we wish to get height and width for generated rendition image we can try the above solution which I posted.
Regards,
Santosh
Agreed with @SantoshSai
Hi @SantoshSai
I request you to please have a look at the rendition's metadata under the jcr:content
Thanks,
Kiran Vedantam.
Hi @Kiran_Vedantam
But unfortunately, I don't have a metadata node for the renditions. the only original image has.
Even I don't have such metadata- Verified existing uploaded image and uploaded new image though
The metadata folder for rendition you will see if the renditions are not excluded from DAM Asset workflow which triggered with create and update.
metadata for renditions should be be created, since all metadata info already stored in the original.
Hi @mrudul , Can't you get is just from rendition file name. These renditions are created by width and height only. If you check documentation of any thumbnail creating workflow step, These are created by defining width and height i.e. file name itself contains width and height(other then original or if something customized)
you can original's width and height can be as mention by others.
Try this if works.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies