Last active
February 4, 2018 15:07
-
-
Save sotirisf/2e3097b8c2659b3079f7e1c3b40e8543 to your computer and use it in GitHub Desktop.
Umbraco Responsive Background Images (Extension Method)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Web; | |
using Umbraco.Core.Models; | |
using Umbraco.Web; | |
using Umbraco.Web.Models; | |
namespace DotSee.Common | |
{ | |
public static class ImageExtensions | |
{ | |
public static ImageData GetImageData(this IPublishedContent image) | |
{ | |
ImageData retVal = new ImageData(); | |
var m = (ImageCropDataSet)(image.GetPropertyValue("umbracoFile")); | |
var top = (m!=null && m.FocalPoint != null) ? m.FocalPoint.Top : 0.5m; | |
var left = (m!=null && m.FocalPoint != null) ? m.FocalPoint.Left : 0.5m; | |
retVal.Top = decimal.Round(top * 100, 2, MidpointRounding.AwayFromZero); | |
retVal.Left = decimal.Round(left * 100, 2, MidpointRounding.AwayFromZero); | |
retVal.StyleUid = Guid.NewGuid().ToString(); | |
retVal.Image = image; | |
return (retVal); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment