diff --git a/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs b/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs index 6b3712e39..56e70d797 100644 --- a/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs +++ b/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs @@ -412,8 +412,7 @@ namespace ImageProcessor.Web.HttpModules // Process the Image imageFactory.Load(memoryStream) - .AddQueryString(queryString) - .AutoProcess() + .AutoProcess(queryString) .Save(cachedPath); // Store the response type in the context for later retrieval. @@ -451,7 +450,9 @@ namespace ImageProcessor.Web.HttpModules semaphore.Wait(); // Process the Image - imageFactory.Load(fullPath).AutoProcess().Save(cachedPath); + imageFactory.Load(requestPath) + .AutoProcess(queryString) + .Save(cachedPath); // Store the response type in the context for later retrieval. context.Items[CachedResponseTypeKey] = imageFactory.CurrentImageFormat.MimeType; diff --git a/src/ImageProcessor.Web/NET45/ImageFactoryExtensions.cs b/src/ImageProcessor.Web/NET45/ImageFactoryExtensions.cs index 704373a55..ee51be516 100644 --- a/src/ImageProcessor.Web/NET45/ImageFactoryExtensions.cs +++ b/src/ImageProcessor.Web/NET45/ImageFactoryExtensions.cs @@ -34,10 +34,11 @@ namespace ImageProcessor.Web /// The current instance of the class /// that this method extends. /// + /// The collection of querystring parameters to process. /// /// The current instance of the class. /// - public static ImageFactory AutoProcess(this ImageFactory factory) + public static ImageFactory AutoProcess(this ImageFactory factory, string queryString) { if (factory.ShouldProcess) { @@ -47,7 +48,7 @@ namespace ImageProcessor.Web // Get a list of all graphics processors that have parsed and matched the query string. List graphicsProcessors = ImageProcessorConfiguration.Instance.GraphicsProcessors - .Where(x => x.MatchRegexIndex(factory.QueryString) != int.MaxValue) + .Where(x => x.MatchRegexIndex(queryString) != int.MaxValue) .OrderBy(y => y.SortOrder) .ToList(); diff --git a/src/ImageProcessor.Web/NET45/Processors/Format.cs b/src/ImageProcessor.Web/NET45/Processors/Format.cs index 8e74f6cc3..436361175 100644 --- a/src/ImageProcessor.Web/NET45/Processors/Format.cs +++ b/src/ImageProcessor.Web/NET45/Processors/Format.cs @@ -134,24 +134,30 @@ namespace ImageProcessor.Web.Processors { identifier = identifier.ToLowerInvariant(); string finalIdentifier = identifier.Equals("png8") ? "png" : identifier; + ISupportedImageFormat newFormat = null; ISupportedImageFormat format = ImageProcessorBootstrapper.Instance.SupportedImageFormats .FirstOrDefault(f => f.FileExtensions.Any(e => e.Equals(finalIdentifier, StringComparison.InvariantCultureIgnoreCase))); if (format != null) { - // I wish this wasn't hard-coded but there's no way I can - // find to preserve the palette. - if (identifier.Equals("png8")) + // Return a new instance as we want to use instance properties. + newFormat = Activator.CreateInstance(format.GetType()) as ISupportedImageFormat; + if (newFormat != null) { - format.IsIndexed = true; - } - else if (identifier.Equals("png")) - { - format.IsIndexed = false; + // I wish this wasn't hard-coded but there's no way I can + // find to preserve the palette. + if (identifier.Equals("png8")) + { + newFormat.IsIndexed = true; + } + else if (identifier.Equals("png")) + { + newFormat.IsIndexed = false; + } } } - return format; + return newFormat; } } } \ No newline at end of file diff --git a/src/ImageProcessor/Core/Common/Exceptions/ImageFormatException.cs b/src/ImageProcessor/Core/Common/Exceptions/ImageFormatException.cs index 0469e33d4..e858b6fcc 100644 --- a/src/ImageProcessor/Core/Common/Exceptions/ImageFormatException.cs +++ b/src/ImageProcessor/Core/Common/Exceptions/ImageFormatException.cs @@ -11,6 +11,7 @@ namespace ImageProcessor.Core.Common.Exceptions { using System; + using System.Runtime.Serialization; /// /// The exception that is thrown when loading the supported image format types has failed. diff --git a/src/ImageProcessor/ImageFactory.cs b/src/ImageProcessor/ImageFactory.cs index a9d74ff3f..9a928e541 100644 --- a/src/ImageProcessor/ImageFactory.cs +++ b/src/ImageProcessor/ImageFactory.cs @@ -94,11 +94,6 @@ namespace ImageProcessor /// public string ImagePath { get; private set; } - /// - /// Gets the query-string parameters for web image manipulation. - /// - public string QueryString { get; private set; } - /// /// Gets a value indicating whether the image factory should process the file. /// @@ -182,23 +177,13 @@ namespace ImageProcessor /// public ImageFactory Load(string imagePath) { - // Remove any querystring parameters passed by web requests. - string[] paths = imagePath.Split('?'); - string path = paths[0]; - string query = string.Empty; - - if (paths.Length > 1) + FileInfo fileInfo = new FileInfo(imagePath); + if (fileInfo.Exists) { - query = paths[1]; - } - - if (File.Exists(path)) - { - this.ImagePath = path; - this.QueryString = query; + this.ImagePath = imagePath; // Open a file stream to prevent the need for lock. - using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read)) + using (FileStream fileStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read)) { ISupportedImageFormat format = FormatUtilities.GetFormat(fileStream); @@ -237,6 +222,10 @@ namespace ImageProcessor this.ShouldProcess = true; } } + else + { + throw new FileNotFoundException(imagePath); + } return this; } @@ -267,24 +256,6 @@ namespace ImageProcessor } #region Manipulation - /// - /// Adds a query-string to the image factory to allow auto-processing of remote files. - /// - /// The query-string parameter to process. - /// - /// The current instance of the class. - /// - public ImageFactory AddQueryString(string query) - { - // TODO: Remove this. - if (this.ShouldProcess) - { - this.QueryString = query; - } - - return this; - } - /// /// Changes the opacity of the current image. /// diff --git a/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs b/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs index 36067736c..2520d23de 100644 --- a/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs +++ b/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs @@ -10,6 +10,7 @@ namespace ImageProcessor.Imaging.Formats { + using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; @@ -53,7 +54,9 @@ namespace ImageProcessor.Imaging.Formats if (header.SequenceEqual(buffer.Take(header.Length))) { stream.Position = 0; - return supportedImageFormat; + + // Return a new instance as we want to use instance properties. + return Activator.CreateInstance(supportedImageFormat.GetType()) as ISupportedImageFormat; } } } diff --git a/src/ImageProcessor/Imaging/Formats/JpegFormat.cs b/src/ImageProcessor/Imaging/Formats/JpegFormat.cs index 9447375d9..ca2a3f546 100644 --- a/src/ImageProcessor/Imaging/Formats/JpegFormat.cs +++ b/src/ImageProcessor/Imaging/Formats/JpegFormat.cs @@ -22,6 +22,14 @@ namespace ImageProcessor.Imaging.Formats /// public sealed class JpegFormat : FormatBase { + /// + /// Initializes a new instance of the class. + /// + public JpegFormat() + { + this.Quality = 90; + } + /// /// Gets the file headers. /// diff --git a/src/ImageProcessor/Processors/Format.cs b/src/ImageProcessor/Processors/Format.cs index 43dac6b35..7a2c9ee68 100644 --- a/src/ImageProcessor/Processors/Format.cs +++ b/src/ImageProcessor/Processors/Format.cs @@ -13,11 +13,7 @@ namespace ImageProcessor.Processors #region Using using System.Collections.Generic; using System.Drawing; - using System.Drawing.Imaging; - using System.Text.RegularExpressions; - using ImageProcessor.Imaging.Formats; - #endregion ///