Get Image width and height

Jignesh Patel asked on November 12, 2015 01:20


I have a document which has field

Name: HeroImage Data type: File Form control: Upload File (restrict file type .jpg;.png.;.gif)

In transformation I am doing something like

<img src="{% GetFileUrlByGUID(HeroImage, NodeAlias) %}" alt="{% Name %}" width="210px" height="100px"/>

but I want to get image information like height and width and update hardcoded values of width="210px" and height="100px". Do you know how can I retrieve image information and use in transform?


Kind regards, Jigs

Recent Answers

Timothy Fenton answered on November 12, 2015 10:41

Regrettably, we don't have any macro for returning the image size as we are using query string parameters to manipulate the images. But you still have an option to create Custom macro in your transformation here.

Within the custom macro, you can query CMS_Attachment table and get AttachmentImageWidth and AttachmentImageHeight properties. and return then back, you could even separate them into two macro methods so you could do each individually

1 votesVote for this answer Mark as a Correct answer

Boris Pocatko answered on November 18, 2015 05:48

I am not sure why you need to do this, but Kentico allows you to re-size the image on thy fly by adding specific query string parameters. That way the image will be always a given size, so you don't have to get the image dimensions on the fly. You can check our documentation for details.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.