How to read media library image dimensions

Tim Valdez asked on January 24, 2024 20:33

I’m working on implementing OpenGraph meta tags on a custom MVC website that uses a Kentico 11 backend, and I want to read the size dimensions of a media library image and store them in fields of a custom Page Type. I’m using the Media Selection control to allow the content creators to select an image from the Media Library, but I don’t see an easy way to also capture the image dimensions. Is there a way to capture those values as well? Right now I’m looking at adding a custom plugin using a global event handler, but I’d love it if there was a simpler way to go about it. Thanks!

Recent Answers

Juraj Ondrus answered on January 25, 2024 07:28

If you have the media file object - the media selection stores either GUID or path, so you should be able to get the object info using the API. Then, the media file info object has the FileImageWidth and FileImageHeight properties you can use.

0 votesVote for this answer Mark as a Correct answer

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