Skip to content

Instantly share code, notes, and snippets.

@sotirisf
Last active February 4, 2018 15:07
Show Gist options
  • Save sotirisf/2e3097b8c2659b3079f7e1c3b40e8543 to your computer and use it in GitHub Desktop.
Save sotirisf/2e3097b8c2659b3079f7e1c3b40e8543 to your computer and use it in GitHub Desktop.
Umbraco Responsive Background Images (Extension Method)
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