[MGNLDAM-720] Provide an easy way to get image width, height and meta data Created: 22/Aug/17  Updated: 12/Jul/21  Resolved: 12/Jul/21

Status: Closed
Project: Magnolia DAM Module
Component/s: DAM Templating
Affects Version/s: 2.2.5
Fix Version/s: None

Type: Improvement Priority: Neutral
Reporter: Viet Nguyen Assignee: Unassigned
Resolution: Workaround exists Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
causality
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Release notes required:
Yes
Documentation update required:
Yes
Date of First Response:

 Description   

Due to request from support, after checking with our KB, we didn't have an explicit support for this on either documentation or codebase:

From earlier Magnolia versions I know a way via model class...

PropertyUtil.getLong(AssetNodeTypes.AssetResource.getResourceNodeFromAsset(node), AssetNodeTypes.AssetResource.WIDTH, 0l);

But this is slightly complicated. You need your own model class and so on... Is there simple way to retrieve the image width/height directly inside FTL template?

Workaround
Using damfn you can get the Asset object which has a getMetadata() method. The MagnoliaAssetMetadata has both getWidth() and getHeight() methods.



 Comments   
Comment by Viet Nguyen [ 22/Aug/17 ]
  • Work around here, thanks to hieu.nguyen:
    [#assign myAsset = damfn.getAsset("jcr", "photos/pool.jpg")!]
    [#assign myAssetMap = damfn.getAssetMap(myAsset)]
    ${myAssetMap.metadata.mgnl.width}
    
Comment by Vivian Steller [ 06/May/20 ]

@Viet Nguyen the workaround (and I think also not even the original suggestion in the description) does not work for PNGs... it's veeeery frustrating that determining the dimension of an image requires that much effort, that's a pity.

Generated at Mon Feb 12 05:02:36 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.