diff --git a/build/Build.bat b/build/Build.bat index 93e60ce61..61973a204 100644 --- a/build/Build.bat +++ b/build/Build.bat @@ -1,7 +1,7 @@ @ECHO OFF -SET version=1.9.2.0 -SET webversion=3.2.6.0 -SET webconfigversion=1.1.1.0 +SET version=1.9.3.0 +SET webversion=3.2.7.0 +SET webconfigversion=1.1.2.0 ECHO Building ImageProcessor %version%, ImageProcess.Web %webversion% and ImageProcess.Web.Config %webconfigversion% diff --git a/build/NuSpecs/ImageProcessor.Web.Config.nuspec b/build/NuSpecs/ImageProcessor.Web.Config.nuspec index d20d8fc73..cb27a3fb2 100644 --- a/build/NuSpecs/ImageProcessor.Web.Config.nuspec +++ b/build/NuSpecs/ImageProcessor.Web.Config.nuspec @@ -21,12 +21,12 @@ Feedback is always welcome Image Imaging ASP Performance Processing HttpModule Cache Resize Rotate RoundedCorners Flip Crop Filter Effects Quality Watermark Alpha Vignette Saturation Brightness Contrast Gif Jpg Jpeg Bitmap Png Fluent GDI Gaussian Blur Sharpen Tint Quantizer Animated - - + + - - + + diff --git a/build/NuSpecs/ImageProcessor.Web.nuspec b/build/NuSpecs/ImageProcessor.Web.nuspec index 78dec17d9..5e640a422 100644 --- a/build/NuSpecs/ImageProcessor.Web.nuspec +++ b/build/NuSpecs/ImageProcessor.Web.nuspec @@ -22,15 +22,15 @@ Feedback is always welcome James South en-GB - Image Imaging ASP Performance Processing HttpModule Cache Resize Rotate RoundedCorners Flip Crop Filter Effects Quality Watermark Alpha Vignette Saturation Brightness Contrast Gif Jpg Jpeg Bitmap Png Fluent GDI Gaussian Blur Sharpen Tint Quantizer Animated + Image Imaging ASP Performance Processing HttpModule Cache Resize AutoRotate Rotate RoundedCorners Flip Crop Filter Effects Quality Watermark Alpha Vignette Saturation Brightness Contrast Gif Jpg Jpeg Bitmap Png Fluent GDI Gaussian Blur Sharpen Tint Quantizer Animated EXIF - - + + - + diff --git a/build/NuSpecs/ImageProcessor.nuspec b/build/NuSpecs/ImageProcessor.nuspec index 757d7a76c..80bdd79a1 100644 --- a/build/NuSpecs/ImageProcessor.nuspec +++ b/build/NuSpecs/ImageProcessor.nuspec @@ -21,7 +21,7 @@ Feedback is always welcome. James South en-GB - Image Imaging ASP Performance Processing Resize Rotate RoundedCorners Flip Crop Filter Effects Quality Watermark Alpha Vignette Saturation Brightness Contrast Gif Jpg Jpeg Bitmap Png Fluent GDI Gaussian Blur Sharpen Tint Quantizer Animated + Image Imaging ASP Performance Processing Resize AutoRotate Rotate RoundedCorners Flip Crop Filter Effects Quality Watermark Alpha Vignette Saturation Brightness Contrast Gif Jpg Jpeg Bitmap Png Fluent GDI Gaussian Blur Sharpen Tint Quantizer Animated EXIF diff --git a/src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj b/src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj index 4432f1f25..cad554bb4 100644 --- a/src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj +++ b/src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj @@ -59,15 +59,16 @@ - ..\..\packages\Microsoft.Bcl.1.1.8\lib\net40\System.IO.dll + ..\..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.IO.dll + True - ..\..\packages\Microsoft.Bcl.1.1.8\lib\net40\System.Runtime.dll + ..\..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.Runtime.dll - ..\..\packages\Microsoft.Bcl.1.1.8\lib\net40\System.Threading.Tasks.dll + ..\..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.Threading.Tasks.dll diff --git a/src/ImageProcessor.Web/NET4/app.config b/src/ImageProcessor.Web/NET4/app.config index d7f44b988..31d365ae5 100644 --- a/src/ImageProcessor.Web/NET4/app.config +++ b/src/ImageProcessor.Web/NET4/app.config @@ -4,11 +4,11 @@ - + - + diff --git a/src/ImageProcessor.Web/NET4/packages.config b/src/ImageProcessor.Web/NET4/packages.config index fd0874c23..c7068f590 100644 --- a/src/ImageProcessor.Web/NET4/packages.config +++ b/src/ImageProcessor.Web/NET4/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/src/ImageProcessor.Web/NET45/Caching/CacheIndexer.cs b/src/ImageProcessor.Web/NET45/Caching/CacheIndexer.cs index 6e975dbd3..cd40c9439 100644 --- a/src/ImageProcessor.Web/NET45/Caching/CacheIndexer.cs +++ b/src/ImageProcessor.Web/NET45/Caching/CacheIndexer.cs @@ -114,8 +114,7 @@ namespace ImageProcessor.Web.Caching { Key = Path.GetFileNameWithoutExtension(cachePath), Path = cachePath, - CreationTimeUtc = fileInfo.CreationTimeUtc, - LastWriteTimeUtc = fileInfo.LastWriteTimeUtc + CreationTimeUtc = fileInfo.CreationTimeUtc }; } } diff --git a/src/ImageProcessor.Web/NET45/Caching/CachedImage.cs b/src/ImageProcessor.Web/NET45/Caching/CachedImage.cs index 592d84eb4..f775ac1c8 100644 --- a/src/ImageProcessor.Web/NET45/Caching/CachedImage.cs +++ b/src/ImageProcessor.Web/NET45/Caching/CachedImage.cs @@ -33,10 +33,5 @@ namespace ImageProcessor.Web.Caching /// Gets or sets the creation time of the cached image. /// public DateTime CreationTimeUtc { get; set; } - - /// - /// Gets or sets the last write time of the cached image. - /// - public DateTime LastWriteTimeUtc { get; set; } } } diff --git a/src/ImageProcessor.Web/NET45/Caching/DiskCache.cs b/src/ImageProcessor.Web/NET45/Caching/DiskCache.cs index 5b0562dc6..88ffe7d48 100644 --- a/src/ImageProcessor.Web/NET45/Caching/DiskCache.cs +++ b/src/ImageProcessor.Web/NET45/Caching/DiskCache.cs @@ -14,13 +14,12 @@ namespace ImageProcessor.Web.Caching using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - using System.Globalization; using System.IO; using System.Linq; + using System.Security.Cryptography; using System.Threading.Tasks; using System.Web; using System.Web.Hosting; - using ImageProcessor.Core.Common.Extensions; using ImageProcessor.Web.Configuration; using ImageProcessor.Web.Helpers; @@ -52,8 +51,7 @@ namespace ImageProcessor.Web.Caching /// /// The absolute path to virtual cache path on the server. /// - private static readonly string AbsoluteCachePath = - HostingEnvironment.MapPath(ImageProcessorConfiguration.Instance.VirtualCachePath); + private static readonly string AbsoluteCachePath = HostingEnvironment.MapPath(ImageProcessorConfig.Instance.VirtualCachePath); /// /// The request for the image. @@ -142,18 +140,14 @@ namespace ImageProcessor.Web.Caching /// /// Adds an image to the cache. /// - /// - /// The creation and last write times. - /// - internal void AddImageToCache(Tuple creationAndLastWriteDateTimes) + internal void AddImageToCache() { string key = Path.GetFileNameWithoutExtension(this.CachedPath); CachedImage cachedImage = new CachedImage { Key = key, Path = this.CachedPath, - CreationTimeUtc = creationAndLastWriteDateTimes.Item1, - LastWriteTimeUtc = creationAndLastWriteDateTimes.Item2 + CreationTimeUtc = DateTime.UtcNow }; CacheIndexer.Add(cachedImage); @@ -196,26 +190,7 @@ namespace ImageProcessor.Web.Caching // Test now for locally requested files. cachedImage = await CacheIndexer.GetValueAsync(path); - if (cachedImage != null) - { - FileInfo imageFileInfo = new FileInfo(this.requestPath); - - if (imageFileInfo.Exists) - { - // Pull the latest info. - imageFileInfo.Refresh(); - - // Check to see if the last write time is different of whether the - // cached image is set to expire or if the max age is different. - if (!this.RoughDateTimeCompare(imageFileInfo.LastWriteTimeUtc, cachedImage.LastWriteTimeUtc) - || this.IsExpired(cachedImage.CreationTimeUtc)) - { - CacheIndexer.Remove(path); - isUpdated = true; - } - } - } - else + if (cachedImage == null) { // Nothing in the cache so we should return true. isUpdated = true; @@ -225,38 +200,6 @@ namespace ImageProcessor.Web.Caching return isUpdated; } - /// - /// Gets the set to the last write time of the file. - /// - /// - /// The last write time of the file. - /// - internal async Task GetLastWriteTimeAsync() - { - DateTime dateTime = DateTime.UtcNow; - - CachedImage cachedImage = await CacheIndexer.GetValueAsync(this.CachedPath); - - if (cachedImage != null) - { - dateTime = cachedImage.LastWriteTimeUtc; - } - - return dateTime; - } - - /// - /// Sets the LastWriteTime of the cached file to match the original file. - /// - /// - /// The set to the last write time of the file. - /// - internal async Task> SetCachedLastWriteTimeAsync() - { - // Create Action delegate for SetCachedLastWriteTime. - return await TaskHelpers.Run(() => this.SetCachedLastWriteTime()); - } - /// /// Trims a cached folder ensuring that it does not exceed the maximum file count. /// @@ -273,46 +216,6 @@ namespace ImageProcessor.Web.Caching #endregion #region Private - /// - /// Sets the LastWriteTime of the cached file to match the original file. - /// - /// - /// The of the original and cached file. - /// - private Tuple SetCachedLastWriteTime() - { - FileInfo cachedFileInfo = new FileInfo(this.CachedPath); - - // DateTime.Min explodes when used east of GMT. - DateTime baseDateTime = DateTime.UtcNow; - DateTime creationTime = baseDateTime; - DateTime lastWriteTime = baseDateTime; - - if (this.isRemote) - { - if (cachedFileInfo.Exists) - { - creationTime = cachedFileInfo.CreationTimeUtc; - lastWriteTime = cachedFileInfo.LastWriteTimeUtc; - } - } - else - { - FileInfo imageFileInfo = new FileInfo(this.requestPath); - - if (imageFileInfo.Exists && cachedFileInfo.Exists) - { - DateTime dateTime = imageFileInfo.LastWriteTimeUtc; - creationTime = cachedFileInfo.CreationTimeUtc; - - cachedFileInfo.LastWriteTimeUtc = dateTime; - lastWriteTime = dateTime; - } - } - - return new Tuple(creationTime, lastWriteTime); - } - /// /// Trims a cached folder ensuring that it does not exceed the maximum file count. /// @@ -368,15 +271,43 @@ namespace ImageProcessor.Web.Caching private string GetCachePath() { string cachedPath = string.Empty; + string streamHash = string.Empty; if (AbsoluteCachePath != null) { + try + { + if (new Uri(this.requestPath).IsFile) + { + // Get the hash for the filestream. That way we can ensure that if the image is + // updated but has the same name we will know. + FileInfo imageFileInfo = new FileInfo(this.requestPath); + if (imageFileInfo.Exists) + { + // Pull the latest info. + imageFileInfo.Refresh(); + using (MD5 md5 = MD5.Create()) + { + using (FileStream stream = File.OpenRead(imageFileInfo.FullName)) + { + byte[] hash = md5.ComputeHash(stream); + streamHash = BitConverter.ToString(hash); + } + } + } + } + } + catch + { + streamHash = string.Empty; + } + // Use an sha1 hash of the full path including the querystring to create the image name. // That name can also be used as a key for the cached image and we should be able to use // The characters of that hash as subfolders. string parsedExtension = ImageHelpers.GetExtension(this.fullPath); string fallbackExtension = this.imageName.Substring(this.imageName.LastIndexOf(".", StringComparison.Ordinal) + 1); - string encryptedName = this.fullPath.ToSHA1Fingerprint(); + string encryptedName = (streamHash + this.fullPath).ToSHA1Fingerprint(); // Collision rate of about 1 in 10000 for the folder structure. string pathFromKey = string.Join("\\", encryptedName.ToCharArray().Take(6)); @@ -392,28 +323,6 @@ namespace ImageProcessor.Web.Caching return cachedPath; } - /// - /// The rough date time compare. - /// - /// - /// The first. - /// - /// - /// The second. - /// - /// - /// The true if the DateTimes roughly compare; otherwise, false. - /// - private bool RoughDateTimeCompare(DateTime first, DateTime second) - { - if (first.ToString(CultureInfo.InvariantCulture) == second.ToString(CultureInfo.InvariantCulture)) - { - return true; - } - - return false; - } - /// /// Gets a value indicating whether the given images creation date is out with /// the prescribed limit. diff --git a/src/ImageProcessor.Web/NET45/Configuration/Resources/processing - Copy.config b/src/ImageProcessor.Web/NET45/Configuration/Resources/processing - Copy.config deleted file mode 100644 index 562cafcb8..000000000 --- a/src/ImageProcessor.Web/NET45/Configuration/Resources/processing - Copy.config +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/ImageProcessor.Web/NET45/Configuration/Resources/processing.config b/src/ImageProcessor.Web/NET45/Configuration/Resources/processing.config index c29cd5db1..3d3aec8f8 100644 --- a/src/ImageProcessor.Web/NET45/Configuration/Resources/processing.config +++ b/src/ImageProcessor.Web/NET45/Configuration/Resources/processing.config @@ -3,6 +3,7 @@ + diff --git a/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs b/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs index 213d35b2a..c751fd095 100644 --- a/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs +++ b/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs @@ -416,11 +416,8 @@ namespace ImageProcessor.Web.HttpModules // Store the response type in the context for later retrieval. context.Items[CachedResponseTypeKey] = imageFactory.CurrentImageFormat.MimeType; - // Ensure that the LastWriteTime property of the source and cached file match. - Tuple creationAndLastWriteDateTimes = await cache.SetCachedLastWriteTimeAsync(); - // Add to the cache. - cache.AddImageToCache(creationAndLastWriteDateTimes); + cache.AddImageToCache(); // Trim the cache. await cache.TrimCachedFolderAsync(cachedPath); @@ -456,11 +453,8 @@ namespace ImageProcessor.Web.HttpModules // Store the response type in the context for later retrieval. context.Items[CachedResponseTypeKey] = imageFactory.CurrentImageFormat.MimeType; - // Ensure that the LastWriteTime property of the source and cached file match. - Tuple creationAndLastWriteDateTimes = await cache.SetCachedLastWriteTimeAsync(); - // Add to the cache. - cache.AddImageToCache(creationAndLastWriteDateTimes); + cache.AddImageToCache(); // Trim the cache. await cache.TrimCachedFolderAsync(cachedPath); diff --git a/src/ImageProcessor.Web/NET45/Processors/AutoRotate.cs b/src/ImageProcessor.Web/NET45/Processors/AutoRotate.cs new file mode 100644 index 000000000..7589becc3 --- /dev/null +++ b/src/ImageProcessor.Web/NET45/Processors/AutoRotate.cs @@ -0,0 +1,83 @@ +namespace ImageProcessor.Web.Processors +{ + using System.Text.RegularExpressions; + using ImageProcessor.Processors; + + /// + /// Performs auto-rotation to ensure that EXIF defined rotation is reflected in + /// the final image. + /// + public class AutoRotate : IWebGraphicsProcessor + { + /// + /// The regular expression to search strings for. + /// + private static readonly Regex QueryRegex = new Regex(@"autorotate=true", RegexOptions.Compiled); + + /// + /// Initializes a new instance of the class. + /// + public AutoRotate() + { + this.Processor = new ImageProcessor.Processors.AutoRotate(); + } + + /// + /// Gets the regular expression to search strings for. + /// + public Regex RegexPattern + { + get + { + return QueryRegex; + } + } + + /// + /// Gets the order in which this processor is to be used in a chain. + /// + public int SortOrder + { + get; + private set; + } + + /// + /// Gets the associated graphics processor. + /// + public IGraphicsProcessor Processor { get; private set; } + + /// + /// The position in the original string where the first character of the captured substring was found. + /// + /// + /// The query string to search. + /// + /// + /// The zero-based starting position in the original string where the captured substring was found. + /// + public int MatchRegexIndex(string queryString) + { + int index = 0; + + // Set the sort order to max to allow filtering. + this.SortOrder = int.MaxValue; + + foreach (Match match in this.RegexPattern.Matches(queryString)) + { + if (match.Success) + { + if (index == 0) + { + // Set the index on the first instance only. + this.SortOrder = match.Index; + } + + index += 1; + } + } + + return this.SortOrder; + } + } +} \ No newline at end of file diff --git a/src/ImageProcessor.Web/NET45/Properties/AssemblyInfo.cs b/src/ImageProcessor.Web/NET45/Properties/AssemblyInfo.cs index 39c9a7e94..8763d6242 100644 --- a/src/ImageProcessor.Web/NET45/Properties/AssemblyInfo.cs +++ b/src/ImageProcessor.Web/NET45/Properties/AssemblyInfo.cs @@ -35,5 +35,5 @@ using ImageProcessor.Web.HttpModules; // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("3.2.6.0")] -[assembly: AssemblyFileVersion("3.2.6.0")] \ No newline at end of file +[assembly: AssemblyVersion("3.2.7.0")] +[assembly: AssemblyFileVersion("3.2.7.0")] \ No newline at end of file diff --git a/src/ImageProcessor/ImageFactory.cs b/src/ImageProcessor/ImageFactory.cs index 1112c2e22..dbad66309 100644 --- a/src/ImageProcessor/ImageFactory.cs +++ b/src/ImageProcessor/ImageFactory.cs @@ -169,12 +169,10 @@ namespace ImageProcessor format.Quality = DefaultQuality; format.IsIndexed = ImageUtils.IsIndexed(this.Image); - if (this.PreserveExifData) + // Always load the data. + foreach (PropertyItem propertyItem in this.Image.PropertyItems) { - foreach (PropertyItem propertyItem in this.Image.PropertyItems) - { - this.ExifPropertyItems[propertyItem.Id] = propertyItem; - } + this.ExifPropertyItems[propertyItem.Id] = propertyItem; } this.ShouldProcess = true; @@ -239,12 +237,10 @@ namespace ImageProcessor this.OriginalExtension = Path.GetExtension(this.ImagePath); - if (this.PreserveExifData) + // Always load the data. + foreach (PropertyItem propertyItem in this.Image.PropertyItems) { - foreach (PropertyItem propertyItem in this.Image.PropertyItems) - { - this.ExifPropertyItems[propertyItem.Id] = propertyItem; - } + this.ExifPropertyItems[propertyItem.Id] = propertyItem; } this.ShouldProcess = true; @@ -325,6 +321,24 @@ namespace ImageProcessor return this; } + /// + /// Performs auto-rotation to ensure that EXIF defined rotation is reflected in + /// the final image. + /// + /// + /// The current instance of the class. + /// + public ImageFactory AutoRotate() + { + if (this.ShouldProcess) + { + AutoRotate autoRotate = new AutoRotate(); + this.ApplyProcessor(autoRotate.ProcessImage); + } + + return this; + } + /// /// Changes the brightness of the current image. /// @@ -413,7 +427,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - CropLayer cropLayer = new CropLayer(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom, CropMode.Pixels); + CropLayer cropLayer = new CropLayer(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height, CropMode.Pixels); return this.Crop(cropLayer); } diff --git a/src/ImageProcessor/ImageProcessor.csproj b/src/ImageProcessor/ImageProcessor.csproj index 68f6e06bd..4cac9981b 100644 --- a/src/ImageProcessor/ImageProcessor.csproj +++ b/src/ImageProcessor/ImageProcessor.csproj @@ -76,7 +76,6 @@ - @@ -112,6 +111,7 @@ + diff --git a/src/ImageProcessor/Imaging/Filters/BlackWhiteMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/BlackWhiteMatrixFilter.cs index 0d3920b14..106c1821d 100644 --- a/src/ImageProcessor/Imaging/Filters/BlackWhiteMatrixFilter.cs +++ b/src/ImageProcessor/Imaging/Filters/BlackWhiteMatrixFilter.cs @@ -11,10 +11,6 @@ namespace ImageProcessor.Imaging.Filters { #region Using - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; using System.Drawing; using System.Drawing.Imaging; #endregion diff --git a/src/ImageProcessor/Imaging/Filters/ColorMatrixes.cs b/src/ImageProcessor/Imaging/Filters/ColorMatrixes.cs index fd54cef22..b1471fee0 100644 --- a/src/ImageProcessor/Imaging/Filters/ColorMatrixes.cs +++ b/src/ImageProcessor/Imaging/Filters/ColorMatrixes.cs @@ -21,37 +21,38 @@ namespace ImageProcessor.Imaging.Filters internal static class ColorMatrixes { /// - /// Gets Sepia. + /// Gets the for generating the sepia filter. /// internal static ColorMatrix Sepia { get { - return new ColorMatrix( - new float[][] + return + new ColorMatrix( + new[] { - new float[] { .393f, .349f, .272f, 0, 0 }, - new float[] { .769f, .686f, .534f, 0, 0 }, - new float[] { .189f, .168f, .131f, 0, 0 }, + new[] { .393f, .349f, .272f, 0, 0 }, + new[] { .769f, .686f, .534f, 0, 0 }, + new[] { .189f, .168f, .131f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 } - }); + }); } } /// - /// Gets BlackWhite. + /// Gets the for generating the black and white filter. /// internal static ColorMatrix BlackWhite { get { return new ColorMatrix( - new float[][] + new[] { - new float[] { 1.5f, 1.5f, 1.5f, 0, 0 }, - new float[] { 1.5f, 1.5f, 1.5f, 0, 0 }, - new float[] { 1.5f, 1.5f, 1.5f, 0, 0 }, + new[] { 1.5f, 1.5f, 1.5f, 0, 0 }, + new[] { 1.5f, 1.5f, 1.5f, 0, 0 }, + new[] { 1.5f, 1.5f, 1.5f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { -1, -1, -1, 0, 1 } }); @@ -59,57 +60,56 @@ namespace ImageProcessor.Imaging.Filters } /// - /// Gets Polaroid. + /// Gets the for generating the polaroid filter. /// internal static ColorMatrix Polaroid { get { return new ColorMatrix( - new float[][] + new[] { - new float[] { 1.638f, -0.062f, -0.262f, 0, 0 }, - new float[] { -0.122f, 1.378f, -0.122f, 0, 0 }, - new float[] { 1.016f, -0.016f, 1.383f, 0, 0 }, + new[] { 1.638f, -0.062f, -0.262f, 0, 0 }, + new[] { -0.122f, 1.378f, -0.122f, 0, 0 }, + new[] { 1.016f, -0.016f, 1.383f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, - new float[] { 0.06f, -0.05f, -0.05f, 0, 1 } + new[] { 0.06f, -0.05f, -0.05f, 0, 1 } }); } } /// - /// Gets Lomograph. + /// Gets the for generating the lomograph filter. /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "Reviewed. Suppression is OK here.")] internal static ColorMatrix Lomograph { get { return new ColorMatrix( - new float[][] + new[] { - new float[] { 1.50f, 0, 0, 0, 0 }, - new float[] { 0, 1.45f, 0, 0, 0 }, - new float[] { 0, 0, 1.09f, 0, 0 }, + new[] { 1.50f, 0, 0, 0, 0 }, + new[] { 0, 1.45f, 0, 0, 0 }, + new[] { 0, 0, 1.09f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, - new float[] { -0.10f, 0.05f, -0.08f, 0, 1 } + new[] { -0.10f, 0.05f, -0.08f, 0, 1 } }); } } /// - /// Gets GreyScale. + /// Gets the for generating the greyscale filter. /// internal static ColorMatrix GreyScale { get { return new ColorMatrix( - new float[][] + new[] { - new float[] { .33f, .33f, .33f, 0, 0 }, - new float[] { .59f, .59f, .59f, 0, 0 }, - new float[] { .11f, .11f, .11f, 0, 0 }, + new[] { .33f, .33f, .33f, 0, 0 }, + new[] { .59f, .59f, .59f, 0, 0 }, + new[] { .11f, .11f, .11f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 } }); @@ -117,14 +117,14 @@ namespace ImageProcessor.Imaging.Filters } /// - /// Gets Invert. + /// Gets the for generating the invert filter. /// internal static ColorMatrix Invert { get { return new ColorMatrix( - new float[][] + new[] { new float[] { -1, 0, 0, 0, 0 }, new float[] { 0, -1, 0, 0, 0 }, @@ -136,7 +136,7 @@ namespace ImageProcessor.Imaging.Filters } /// - /// Gets HiSatch. + /// Gets the for generating the high saturation filter. /// [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "Reviewed. Suppression is OK here.")] internal static ColorMatrix HiSatch @@ -144,7 +144,7 @@ namespace ImageProcessor.Imaging.Filters get { return new ColorMatrix( - new float[][] + new[] { new float[] { 3, -1, -1, 0, 0 }, new float[] { -1, 3, -1, 0, 0 }, @@ -156,7 +156,7 @@ namespace ImageProcessor.Imaging.Filters } /// - /// Gets LoSatch. + /// Gets the for generating the low saturation filter. /// [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "Reviewed. Suppression is OK here.")] internal static ColorMatrix LoSatch @@ -164,19 +164,19 @@ namespace ImageProcessor.Imaging.Filters get { return new ColorMatrix( - new float[][] + new[] { new float[] { 1, 0, 0, 0, 0 }, new float[] { 0, 1, 0, 0, 0 }, new float[] { 0, 0, 1, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, - new float[] { .25f, .25f, .25f, 0, 1 } + new[] { .25f, .25f, .25f, 0, 1 } }); } } /// - /// Gets for generating the high pass + /// Gets the for generating the high pass /// on the comic book filter. /// internal static ColorMatrix ComicHigh @@ -184,11 +184,11 @@ namespace ImageProcessor.Imaging.Filters get { return new ColorMatrix( - new float[][] + new[] { - new float[] { 2, -0.5f, -0.5f, 0, 0 }, - new float[] { -0.5f, 2, -0.5f, 0, 0 }, - new float[] { -0.5f, -0.5f, 2, 0, 0 }, + new[] { 2, -0.5f, -0.5f, 0, 0 }, + new[] { -0.5f, 2, -0.5f, 0, 0 }, + new[] { -0.5f, -0.5f, 2, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 } }); @@ -204,16 +204,15 @@ namespace ImageProcessor.Imaging.Filters get { return new ColorMatrix( - new float[][] + new[] { new float[] { 1, 0, 0, 0, 0 }, new float[] { 0, 1, 0, 0, 0 }, new float[] { 0, 0, 1, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, - new float[] { .075f, .075f, .075f, 0, 1 } + new[] { .075f, .075f, .075f, 0, 1 } }); } } - } } diff --git a/src/ImageProcessor/Imaging/Filters/ComicMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/ComicMatrixFilter.cs index 7c7feab83..86fead676 100644 --- a/src/ImageProcessor/Imaging/Filters/ComicMatrixFilter.cs +++ b/src/ImageProcessor/Imaging/Filters/ComicMatrixFilter.cs @@ -17,9 +17,7 @@ namespace ImageProcessor.Imaging.Filters using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Runtime.InteropServices; - using ImageProcessor.Core.Common.Extensions; - #endregion /// @@ -38,16 +36,6 @@ namespace ImageProcessor.Imaging.Filters /// Blue = 0, - /// - /// The green channel - /// - Green = 1, - - /// - /// The red channel - /// - Red = 2, - /// /// The alpha channel /// diff --git a/src/ImageProcessor/Processors/AutoRotate.cs b/src/ImageProcessor/Processors/AutoRotate.cs new file mode 100644 index 000000000..0ec872bb5 --- /dev/null +++ b/src/ImageProcessor/Processors/AutoRotate.cs @@ -0,0 +1,99 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Performs auto-rotation to ensure that EXIF defined rotation is reflected in +// the final image. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.Processors +{ + using System.Collections.Generic; + using System.Drawing; + using ImageProcessor.Imaging; + + /// + /// Performs auto-rotation to ensure that EXIF defined rotation is reflected in + /// the final image. + /// + public class AutoRotate : IGraphicsProcessor + { + /// + /// Gets or sets DynamicParameter. + /// + public dynamic DynamicParameter + { + get; + set; + } + + /// + /// Gets or sets any additional settings required by the processor. + /// + public Dictionary Settings + { + get; + set; + } + + /// + /// Processes the image. + /// + /// The the current instance of the + /// class containing + /// the image to process. + /// + /// The processed image from the current instance of the class. + /// + public Image ProcessImage(ImageFactory factory) + { + Bitmap newImage = null; + Image image = factory.Image; + + try + { + const int Orientation = (int)ExifPropertyTag.Orientation; + if (!factory.PreserveExifData && factory.ExifPropertyItems.ContainsKey(Orientation)) + { + newImage = new Bitmap(image); + + int rotationValue = factory.ExifPropertyItems[Orientation].Value[0]; + switch (rotationValue) + { + case 1: // Landscape, do nothing + break; + + case 8: // Rotated 90 right + // De-rotate: + newImage.RotateFlip(RotateFlipType.Rotate270FlipNone); + break; + + case 3: // Bottoms up + newImage.RotateFlip(RotateFlipType.Rotate180FlipNone); + break; + + case 6: // Rotated 90 left + newImage.RotateFlip(RotateFlipType.Rotate90FlipNone); + break; + } + + // Reassign the image. + image.Dispose(); + image = newImage; + } + } + catch + { + if (newImage != null) + { + newImage.Dispose(); + } + } + + return image; + } + } +} \ No newline at end of file diff --git a/src/ImageProcessor/Properties/AssemblyInfo.cs b/src/ImageProcessor/Properties/AssemblyInfo.cs index 8b03506f0..bea6c1401 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.9.2.0")] -[assembly: AssemblyFileVersion("1.9.2.0")] +[assembly: AssemblyVersion("1.9.3.0")] +[assembly: AssemblyFileVersion("1.9.3.0")] diff --git a/src/ImageProcessor/Settings.StyleCop b/src/ImageProcessor/Settings.StyleCop index 6f5d9d4ab..5a4708f04 100644 --- a/src/ImageProcessor/Settings.StyleCop +++ b/src/ImageProcessor/Settings.StyleCop @@ -9,6 +9,7 @@ exif halftoning lomograph + Lomograph octree png quantizer diff --git a/src/Images/rotate.jpg.REMOVED.git-id b/src/Images/rotate.jpg.REMOVED.git-id new file mode 100644 index 000000000..bf0538b24 --- /dev/null +++ b/src/Images/rotate.jpg.REMOVED.git-id @@ -0,0 +1 @@ +406a6a7916628c0c0bea8243565a7162ebd5a505 \ No newline at end of file diff --git a/src/TestWebsites/NET4/Test_Website_MVC_NET4.csproj b/src/TestWebsites/NET4/Test_Website_MVC_NET4.csproj index b8d3b29dc..6158a3bce 100644 --- a/src/TestWebsites/NET4/Test_Website_MVC_NET4.csproj +++ b/src/TestWebsites/NET4/Test_Website_MVC_NET4.csproj @@ -70,14 +70,14 @@ - ..\..\packages\Microsoft.Bcl.1.1.8\lib\net40\System.IO.dll + ..\..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.IO.dll - ..\..\packages\Microsoft.Bcl.1.1.8\lib\net40\System.Runtime.dll + ..\..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.Runtime.dll - ..\..\packages\Microsoft.Bcl.1.1.8\lib\net40\System.Threading.Tasks.dll + ..\..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.Threading.Tasks.dll diff --git a/src/TestWebsites/NET4/Web.config b/src/TestWebsites/NET4/Web.config index f1a0ba606..1417ff9bf 100644 --- a/src/TestWebsites/NET4/Web.config +++ b/src/TestWebsites/NET4/Web.config @@ -46,7 +46,7 @@ - + @@ -63,13 +63,13 @@ - + - + - + - + diff --git a/src/TestWebsites/NET4/config/imageprocessor/processing.config b/src/TestWebsites/NET4/config/imageprocessor/processing.config index 654a9fbd6..85283e9f2 100644 --- a/src/TestWebsites/NET4/config/imageprocessor/processing.config +++ b/src/TestWebsites/NET4/config/imageprocessor/processing.config @@ -5,6 +5,7 @@ + diff --git a/src/TestWebsites/NET4/packages.config b/src/TestWebsites/NET4/packages.config index fd0874c23..c7068f590 100644 --- a/src/TestWebsites/NET4/packages.config +++ b/src/TestWebsites/NET4/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file