Created
October 4, 2012 17:52
-
-
Save mortenbock/3835255 to your computer and use it in GitHub Desktop.
ImageGen sample implementation
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
namespace UmbImageDemo | |
{ | |
public class ImageUrlProvider : IImageUrlProvider | |
{ | |
public string Name | |
{ | |
get { return "imageGen"; } | |
} | |
public string GetImageUrlFromMedia(int mediaId, IDictionary<string, string> parameters) | |
{ | |
string url = string.Empty; | |
var nodeIterator = library.GetMedia(mediaId, false); | |
if (nodeIterator.Current != null) | |
{ | |
var filename = getProperty(nodeIterator, "umbracoFile"); | |
url = withParams(filename, parameters); | |
} | |
return url; | |
} | |
public string GetImageUrlFromFileName(string specifiedSrc, IDictionary<string, string> parameters) | |
{ | |
return withParams(specifiedSrc, parameters); | |
} | |
private string withParams(string filename, IDictionary<string, string> parameters) | |
{ | |
string urlParams = String.Join("&", parameters.Keys.Select(k => String.Join("=", k, parameters[k]))); | |
return string.Format("/ImageGen.ashx?image={0}&{1}", filename, urlParams); | |
} | |
private static string getProperty(XPathNodeIterator nodeIterator, string fileProp) | |
{ | |
string xpath = UmbracoSettings.UseLegacyXmlSchema | |
? string.Format(".//data[@alias = '{0}']", fileProp) | |
: string.Format(".//{0}", fileProp); | |
var file = nodeIterator.Current.SelectSingleNode(xpath).InnerXml; | |
return file; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment