/// <summary> /// Creates and returns a new collection of <see cref="IWebGraphicsProcessor"/> /// <remarks> /// Creating the processors should be fairly cheap and better for performance than /// locking around the procesors on each request. The System.Drawing.Graphics object still does a lock but that /// isn't used for many procesors. /// </remarks> /// </summary> /// <returns>The <see cref="T:IWebGraphicsProcessor[]"/></returns> public IWebGraphicsProcessor[] CreateWebGraphicsProcessors() { List <IWebGraphicsProcessor> processors = new List <IWebGraphicsProcessor>(); foreach (KeyValuePair <Type, Dictionary <string, string> > pair in this.AvailableWebGraphicsProcessors) { IWebGraphicsProcessor processor = (IWebGraphicsProcessor)Activator.CreateInstance(pair.Key); processor.Processor.Settings = pair.Value; processors.Add(processor); } return(processors.ToArray()); }
/// <summary> /// Auto processes image files based on any query string parameters added to the image path. /// </summary> /// <param name="factory"> /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class /// that this method extends. /// </param> /// <param name="graphicsProcessors">The array of graphics processors to apply.</param> /// <returns> /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// </returns> internal static ImageFactory AutoProcess(this ImageFactory factory, IWebGraphicsProcessor[] graphicsProcessors) { if (factory.ShouldProcess) { // Loop through and process the image. foreach (IWebGraphicsProcessor graphicsProcessor in graphicsProcessors) { factory.CurrentImageFormat.ApplyProcessor(graphicsProcessor.Processor.ProcessImage, factory); } } return factory; }
/// <summary> /// Returns the correct file extension for the given string input /// </summary> /// <param name="fullPath"> /// The string to parse. /// </param> /// <param name="queryString"> /// The querystring containing instructions. /// </param> /// <returns> /// The correct file extension for the given string input if it can find one; otherwise an empty string. /// </returns> public static string GetExtension(string fullPath, string queryString) { Match match = null; // First check to see if the format processor is being used and test against that. IWebGraphicsProcessor format = ImageProcessorConfiguration.Instance.GraphicsProcessors .FirstOrDefault(p => typeof(Format) == p.GetType()); if (format != null) { match = format.RegexPattern.Match(queryString); } if (match == null || !match.Success) { // Test against the path minus the querystring so any other // processors don't interere. string trimmed = fullPath; if (!string.IsNullOrEmpty(queryString)) { trimmed = trimmed.Replace(queryString, string.Empty); } match = FormatRegex.Match(trimmed); } if (match.Success) { string value = match.Value; // Clip if format processor match. if (match.Value.Contains("=")) { value = value.Split('=')[1]; } // Ah the enigma that is the png file. if (value.ToLowerInvariant().EndsWith("png8")) { return("png"); } return(value); } return(string.Empty); }