Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ImageGen sample implementation
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
You can’t perform that action at this time.