-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for presets in addition to manual/individual width param #2
base: master
Are you sure you want to change the base?
Changes from all commits
13a68b2
1da4d7a
9f51409
0949455
83d3e32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ public MarkupParser(System.Text.Encoding encoding) | |
this.TextEncoding = encoding; | ||
} | ||
|
||
public string TransformImgToPicture(string content) | ||
public string TransformImgToSlimmage(string content) | ||
{ | ||
try | ||
{ | ||
|
@@ -41,6 +41,20 @@ public string TransformImgToPicture(string content) | |
if ((src != null && src.Value.IndexOf("slimmage=true", StringComparison.InvariantCultureIgnoreCase) > -1) | ||
|| (cls != null && cls.Value.IndexOf("slimmage", StringComparison.InvariantCultureIgnoreCase) > -1)) | ||
{ | ||
// - if no width set with querystring param, but preset name, get the width from the preset | ||
if ((src.Value.IndexOf("width=", StringComparison.InvariantCultureIgnoreCase) == -1) | ||
&& (src.Value.IndexOf("preset=", StringComparison.InvariantCultureIgnoreCase) > -1)) | ||
{ | ||
// - get presets from config | ||
var configSection = WebConfigurationManager.GetSection("resizer") as ImageResizer.ResizerSection; | ||
XmlElement conf = configSection.getCopyOfNode("presets").ToXmlElement(); | ||
// - find preset by name | ||
XmlNode curpreset = conf.SelectSingleNode(string.Format("preset[@name='{0}']/@defaults", System.Web.HttpUtility.ParseQueryString(src.Value.Substring(src.Value.IndexOf("?")))["preset"])); | ||
string presetWidth = System.Web.HttpUtility.ParseQueryString(curpreset.InnerText)["width"]; | ||
|
||
// - append presets's default width to querystring | ||
src.Value = string.Format("{0}&width={1}", src.Value, presetWidth); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably best to expand the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe using just the whole preset string is an option? But any params that are image size related would surely prove difficult then. We could also just with these to additional params for now and have a first version shipped. We can always improve later on, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that slimmage supports height, perhaps we can just apply the preset client-side as if it were server side? No item-specific logic? Perhaps check the preset xml itself for an enabling flag, like 'applyWithSlimResponse'? |
||
} | ||
|
||
// - append fallback image | ||
HtmlNode container = doc.CreateElement("noscript"); | ||
|
@@ -62,7 +76,7 @@ public string TransformImgToPicture(string content) | |
} | ||
catch(Exception ex) | ||
{ | ||
Trace.TraceWarning("SlimResponse failed to parse HTML: " + ex.ToString() + ex.StackTrace); | ||
Trace.TraceWarning("SlimResponse failed to parse HTML: {0} {1}", ex.ToString(), ex.StackTrace); | ||
// - better that nothing(tm) ... | ||
//return content; | ||
return ex.ToString(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ImageResizer also supports the semicolon syntax, not just querystring, so using
new Instructions()
to parse will enable that. Instructions.Width will return either 'width' and 'w', but not 'maxwidth'.instructions.Get<int>("maxwidth")
lets you access that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the heads up with the semicolon separated instructions! Will fix that.