From 54f0c11e880adf62ba200349b0886f1662091d93 Mon Sep 17 00:00:00 2001 From: James South Date: Wed, 18 Jun 2014 13:50:45 +0100 Subject: [PATCH] v1.9.2, v3.2.7, v1.1.2 - Adds AutoRotate - Fixes ImageProcessor.Crop bug. - Updates cache to be compatible with Azure Image Optimizer Former-commit-id: 6314e378ebcb00ece8b1b5f39c4bfa4524d6cdc2 --- build/Build.bat | 6 +- .../NuSpecs/ImageProcessor.Web.Config.nuspec | 8 +- build/NuSpecs/ImageProcessor.Web.nuspec | 8 +- build/NuSpecs/ImageProcessor.nuspec | 2 +- .../NET4/ImageProcessor.Web_NET4.csproj | 7 +- src/ImageProcessor.Web/NET4/app.config | 4 +- src/ImageProcessor.Web/NET4/packages.config | 2 +- .../NET45/Caching/CacheIndexer.cs | 3 +- .../NET45/Caching/CachedImage.cs | 5 - .../NET45/Caching/DiskCache.cs | 161 ++++-------------- .../HttpModules/ImageProcessingModule.cs | 10 +- .../NET45/Properties/AssemblyInfo.cs | 4 +- src/ImageProcessor/Properties/AssemblyInfo.cs | 4 +- .../NET4/Test_Website_MVC_NET4.csproj | 6 +- src/TestWebsites/NET4/Web.config | 10 +- .../config/imageprocessor/processing.config | 1 + src/TestWebsites/NET4/packages.config | 2 +- 17 files changed, 71 insertions(+), 172 deletions(-) diff --git a/build/Build.bat b/build/Build.bat index 93e60ce612..61973a204b 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 d20d8fc73b..cb27a3fb29 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 78dec17d9b..5e640a422d 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 757d7a76cd..80bdd79a1c 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 4432f1f257..cad554bb4a 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 d7f44b988b..31d365ae59 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 fd0874c230..c7068f5907 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 6e975dbd3c..cd40c94394 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 592d84eb44..f775ac1c8c 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 8052e05401..e48e572075 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.Extensions; using ImageProcessor.Web.Config; 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(ImageProcessorConfig.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. @@ -431,4 +340,4 @@ namespace ImageProcessor.Web.Caching #endregion #endregion } -} +} \ No newline at end of file diff --git a/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs b/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs index efcbdc2edc..22c03bef7e 100644 --- a/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs +++ b/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs @@ -415,11 +415,8 @@ namespace ImageProcessor.Web.HttpModules // Store the response type in the context for later retrieval. context.Items[CachedResponseTypeKey] = imageFactory.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); @@ -455,11 +452,8 @@ namespace ImageProcessor.Web.HttpModules // Store the response type in the context for later retrieval. context.Items[CachedResponseTypeKey] = imageFactory.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/Properties/AssemblyInfo.cs b/src/ImageProcessor.Web/NET45/Properties/AssemblyInfo.cs index 39c9a7e949..8763d62424 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/Properties/AssemblyInfo.cs b/src/ImageProcessor/Properties/AssemblyInfo.cs index 8b03506f0d..bea6c1401b 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/TestWebsites/NET4/Test_Website_MVC_NET4.csproj b/src/TestWebsites/NET4/Test_Website_MVC_NET4.csproj index b8d3b29dcb..6158a3bcef 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 f1a0ba606b..1417ff9bf0 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 654a9fbd65..85283e9f2b 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 fd0874c230..c7068f5907 100644 --- a/src/TestWebsites/NET4/packages.config +++ b/src/TestWebsites/NET4/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file