private static void MapImageWithCropsProperties(ImageWithCrops image, IPublishedContent mediaModel) { try { image.Crops = new Dictionary <string, string>(); foreach (var crop in mediaModel.GetPropertyValue <dynamic>("umbracoFile").crops) { string alias = crop.alias; image.Crops.Add(alias, mediaModel.GetCropUrl(alias)); } } catch { image.Crops = null; } }
public static object GetImageWithCrops(IUmbracoMapper mapper, IPublishedContent contentToMapFrom, string propertyName, bool recursive) { var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); var mediaModel = umbracoHelper.TypedMedia(contentToMapFrom.GetPropertyValue <int>(propertyName)); if (mediaModel == null) { return(null); } var image = new ImageWithCrops(); MapMediaFileProperties(image, mediaModel, mapper.AssetsRootUrl); MapImageProperties(image, mediaModel); MapImageWithCropsProperties(image, mediaModel); return(image); }