Check the API examples at docs.kentico.com/...#Medialibraries-Mediafoldersandfiles
If you have the item GUID you'd do something like:
CMS.MediaLibrary.MediaFileInfo yourfile = CMS.MediaLibrary.MediaFileInfoProvider.GetMediaFileInfo(fileGuid, SiteContext.CurrentSiteName);
or if you just have the path: (you might need to remove the ~
or first /
.)
CMS.MediaLibrary.MediaFileInfo yourfile = CMS.MediaLibrary.MediaFileInfoProvider.GetMediaFiles().Where("FilePath", yourMediaPath).FirstObject();
The media file itself has the following properties:
var imgHeight = yourfile.FileImageHeight;
var imgWidth = yourfile.FileImageWidth;