From 393cf1caa809c1d19f92063fdd9fa77ed4af8315 Mon Sep 17 00:00:00 2001 From: James South Date: Tue, 14 Jan 2014 16:06:13 +0000 Subject: [PATCH] v1.8.1.2 pre - Fixes #28 Sigma parsing error - Format now determines jpeg/jpg & tiff/tif files - Touches #18 Hopeful fix. Former-commit-id: bff79b25501b3a985c54a4753ba781b313d2e844 --- src/ImageProcessor/ImageFactory.cs | 18 +++++++++--------- src/ImageProcessor/Imaging/ImageUtils.cs | 4 ++-- src/ImageProcessor/Processors/Format.cs | 6 ++++-- src/ImageProcessor/Processors/GaussianBlur.cs | 2 +- .../Processors/GaussianSharpen.cs | 3 ++- src/ImageProcessor/Properties/AssemblyInfo.cs | 4 ++-- .../Test_Website_NET45/Views/Home/Index.cshtml | 4 ++-- 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/ImageProcessor/ImageFactory.cs b/src/ImageProcessor/ImageFactory.cs index 43b21998a..91d011d7d 100644 --- a/src/ImageProcessor/ImageFactory.cs +++ b/src/ImageProcessor/ImageFactory.cs @@ -40,11 +40,6 @@ namespace ImageProcessor /// private ImageFormat backupImageFormat; - /// - /// The original extension. - /// - private string originalExtension; - /// /// Whether the image is indexed. /// @@ -110,6 +105,11 @@ namespace ImageProcessor /// Gets the file format of the image. /// public ImageFormat ImageFormat { get; private set; } + + /// + /// Gets or sets the original extension. + /// + internal string OriginalExtension { get; set; } /// /// Gets or sets the quality of output for jpeg images as a percentile. @@ -191,7 +191,7 @@ namespace ImageProcessor this.JpegQuality = DefaultJpegQuality; ImageFormat imageFormat = ImageUtils.GetImageFormat(imageName); this.backupImageFormat = imageFormat; - this.originalExtension = Path.GetExtension(this.ImagePath); + this.OriginalExtension = Path.GetExtension(this.ImagePath); this.ImageFormat = imageFormat; this.isIndexed = ImageUtils.IsIndexed(this.Image); this.ShouldProcess = true; @@ -762,7 +762,7 @@ namespace ImageProcessor // We need to check here if the path has an extension and remove it if so. // This is so we can add the correct image format. int length = filePath.LastIndexOf(".", StringComparison.Ordinal); - string extension = ImageUtils.GetExtensionFromImageFormat(this.ImageFormat, this.originalExtension); + string extension = ImageUtils.GetExtensionFromImageFormat(this.ImageFormat, this.OriginalExtension); filePath = length == -1 ? filePath + extension : filePath.Substring(0, length) + extension; // Fix the colour palette of indexed images. @@ -795,7 +795,7 @@ namespace ImageProcessor this.Image.Save(filePath, imageCodecInfo, encoderParameters); break; } - catch (IOException) + catch (Exception) { Thread.Sleep(200); } @@ -817,7 +817,7 @@ namespace ImageProcessor this.Image.Save(filePath, this.ImageFormat); break; } - catch (IOException) + catch (Exception) { Thread.Sleep(200); } diff --git a/src/ImageProcessor/Imaging/ImageUtils.cs b/src/ImageProcessor/Imaging/ImageUtils.cs index a718a75a6..d60899863 100644 --- a/src/ImageProcessor/Imaging/ImageUtils.cs +++ b/src/ImageProcessor/Imaging/ImageUtils.cs @@ -27,12 +27,12 @@ namespace ImageProcessor.Imaging /// /// The image format regex. /// - private static readonly Regex FormatRegex = new Regex(@"(\.?)(j(pg|peg)|bmp|png|gif|ti(f|ff))", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.RightToLeft); + private static readonly Regex FormatRegex = new Regex(@"(\.?)(j(pg|peg)|bmp|png|gif|ti(ff|f))", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.RightToLeft); /// /// The image format regex for matching the file format at the end of a string. /// - private static readonly Regex EndFormatRegex = new Regex(@"(\.)(j(pg|peg)|bmp|png|gif|ti(f|ff))$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.RightToLeft); + private static readonly Regex EndFormatRegex = new Regex(@"(\.)(j(pg|peg)|bmp|png|gif|ti(ff|f))$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.RightToLeft); /// /// Returns the correct response type based on the given request path. diff --git a/src/ImageProcessor/Processors/Format.cs b/src/ImageProcessor/Processors/Format.cs index 16fc08973..ff8a0dcc0 100644 --- a/src/ImageProcessor/Processors/Format.cs +++ b/src/ImageProcessor/Processors/Format.cs @@ -25,7 +25,7 @@ namespace ImageProcessor.Processors /// /// The regular expression to search strings for. /// - private static readonly Regex QueryRegex = new Regex(@"format=(j(pg|peg)|png|png8|bmp|gif|tif)", RegexOptions.Compiled); + private static readonly Regex QueryRegex = new Regex(@"format=(j(pg|peg)|png|png8|bmp|gif|ti(ff|f))", RegexOptions.Compiled); #region IGraphicsProcessor Members /// @@ -132,15 +132,17 @@ namespace ImageProcessor.Processors isIndexed = true; break; case "tif": + case "tiff": imageFormat = ImageFormat.Tiff; break; default: - // Should be a jpeg. + // Should be a jpeg or jpg. imageFormat = ImageFormat.Jpeg; break; } // Set the internal property. + factory.OriginalExtension = string.Format(".{0}", format); factory.Format(imageFormat, isIndexed); return factory.Image; diff --git a/src/ImageProcessor/Processors/GaussianBlur.cs b/src/ImageProcessor/Processors/GaussianBlur.cs index d6d697508..54b93dc9d 100644 --- a/src/ImageProcessor/Processors/GaussianBlur.cs +++ b/src/ImageProcessor/Processors/GaussianBlur.cs @@ -35,7 +35,7 @@ namespace ImageProcessor.Processors /// /// The sigma regex. /// - private static readonly Regex SigmaRegex = new Regex(@"sigma-\d+(.+\d+)?", RegexOptions.Compiled); + private static readonly Regex SigmaRegex = new Regex(@"sigma-\d+(.?\d+)?", RegexOptions.Compiled); /// /// The threshold regex. diff --git a/src/ImageProcessor/Processors/GaussianSharpen.cs b/src/ImageProcessor/Processors/GaussianSharpen.cs index 5bd4cacab..df20529d2 100644 --- a/src/ImageProcessor/Processors/GaussianSharpen.cs +++ b/src/ImageProcessor/Processors/GaussianSharpen.cs @@ -35,13 +35,14 @@ namespace ImageProcessor.Processors /// /// The sigma regex. /// - private static readonly Regex SigmaRegex = new Regex(@"sigma-\d+(.+\d+)?", RegexOptions.Compiled); + private static readonly Regex SigmaRegex = new Regex(@"sigma-\d+(.?\d+)?", RegexOptions.Compiled); /// /// The threshold regex. /// private static readonly Regex ThresholdRegex = new Regex(@"threshold-\d+", RegexOptions.Compiled); #endregion + #region IGraphicsProcessor Members /// /// Gets the regular expression to search strings for. diff --git a/src/ImageProcessor/Properties/AssemblyInfo.cs b/src/ImageProcessor/Properties/AssemblyInfo.cs index 175d0cb71..74cebea3b 100644 --- a/src/ImageProcessor/Properties/AssemblyInfo.cs +++ b/src/ImageProcessor/Properties/AssemblyInfo.cs @@ -32,6 +32,6 @@ using System.Security; // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.8.1.1")] -[assembly: AssemblyFileVersion("1.8.1.1")] +[assembly: AssemblyVersion("1.8.1.2")] +[assembly: AssemblyFileVersion("1.8.1.2")] diff --git a/src/TestWebsites/NET45/Test_Website_NET45/Views/Home/Index.cshtml b/src/TestWebsites/NET45/Test_Website_NET45/Views/Home/Index.cshtml index 6572d1734..0aa9fc37a 100644 --- a/src/TestWebsites/NET45/Test_Website_NET45/Views/Home/Index.cshtml +++ b/src/TestWebsites/NET45/Test_Website_NET45/Views/Home/Index.cshtml @@ -173,11 +173,11 @@

Gaussian Blur

- +

Gaussian Sharpen

- +