diff --git a/build/NuSpecs/ImageProcessor.Plugins.Cair.nuspec b/build/NuSpecs/ImageProcessor.Plugins.Cair.nuspec index 7e58646c7..941a3d985 100644 --- a/build/NuSpecs/ImageProcessor.Plugins.Cair.nuspec +++ b/build/NuSpecs/ImageProcessor.Plugins.Cair.nuspec @@ -1,31 +1,31 @@  - - ImageProcessor.Plugins.Cair - 1.0.0.0 - ImageProcessor.Plugins.Cair - James South - James South - http://imageprocessor.org - http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png - false - Adds support to ImageProcessor for Content Aware Image Resizing. + + ImageProcessor.Plugins.Cair + 1.0.0.0 + ImageProcessor.Plugins.Cair + James South + James South + http://imageprocessor.org + http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png + false + Adds support to ImageProcessor for Content Aware Image Resizing. If you use ImageProcessor please get in touch via my twitter @james_m_south Feedback is always welcome - Adds support to ImageProcessor for Content Aware Image Resizing. - - James South - en-GB - Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff Cair Seam Carving - - - - - - - - - + Adds support to ImageProcessor for Content Aware Image Resizing. + + James South + en-GB + Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff Cair Seam Carving + + + + + + + + + \ No newline at end of file diff --git a/build/NuSpecs/ImageProcessor.Plugins.WebP.nuspec b/build/NuSpecs/ImageProcessor.Plugins.WebP.nuspec index c916ec021..35dfadfec 100644 --- a/build/NuSpecs/ImageProcessor.Plugins.WebP.nuspec +++ b/build/NuSpecs/ImageProcessor.Plugins.WebP.nuspec @@ -1,32 +1,32 @@  - - ImageProcessor.Plugins.WebP - 1.0.1.0 - ImageProcessor.Plugins.WebP - James South - James South - http://imageprocessor.org - http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png - false - Adds support to ImageProcessor for the WebP image format. + + ImageProcessor.Plugins.WebP + 1.0.1.0 + ImageProcessor.Plugins.WebP + James South + James South + http://imageprocessor.org + http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png + false + Adds support to ImageProcessor for the WebP image format. If you use ImageProcessor please get in touch via my twitter @james_m_south Feedback is always welcome - Adds support to ImageProcessor and ImageProcessor.Web for the WebP image format. - - James South - en-GB - Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff WebP - - - - - - - - - - + Adds support to ImageProcessor and ImageProcessor.Web for the WebP image format. + + James South + en-GB + Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff WebP + + + + + + + + + + \ No newline at end of file diff --git a/build/NuSpecs/ImageProcessor.Web.Config.nuspec b/build/NuSpecs/ImageProcessor.Web.Config.nuspec index 4353c3da4..cccaef207 100644 --- a/build/NuSpecs/ImageProcessor.Web.Config.nuspec +++ b/build/NuSpecs/ImageProcessor.Web.Config.nuspec @@ -1,35 +1,35 @@  - - ImageProcessor.Web.Config - 2.1.0.0 - ImageProcessor.Web.Config - James South - James South - http://imageprocessor.org - http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png - false - Adds configuration to your ImageProcessor.Web solution to allow you to override the default settings. + + ImageProcessor.Web.Config + 2.1.0.0 + ImageProcessor.Web.Config + James South + James South + http://imageprocessor.org + http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png + false + Adds configuration to your ImageProcessor.Web solution to allow you to override the default settings. If you use ImageProcessor please get in touch via my twitter @james_m_south Feedback is always welcome - ImageProcessor.Web configuration settings for ASP.NET websites. - - James South - en-GB - Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff ASP Cache EXIF - - - - - - - - - - - - - + ImageProcessor.Web configuration settings for ASP.NET websites. + + James South + en-GB + Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff ASP Cache EXIF + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/NuSpecs/ImageProcessor.Web.nuspec b/build/NuSpecs/ImageProcessor.Web.nuspec index a1664b8ea..f447c834a 100644 --- a/build/NuSpecs/ImageProcessor.Web.nuspec +++ b/build/NuSpecs/ImageProcessor.Web.nuspec @@ -1,34 +1,34 @@  - - ImageProcessor.Web - 4.1.0.0 - ImageProcessor.Web - James South - James South - http://imageprocessor.org - http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png - false - ImageProcessor.Web adds a configurable HttpModule to your website which allows on-the-fly processing of image files. The module also comes with a file and browser based cache that can handle millions of images, increasing your processing output and saving precious server memory. + + ImageProcessor.Web + 4.1.1.0 + ImageProcessor.Web + James South + James South + http://imageprocessor.org + http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png + false + ImageProcessor.Web adds a configurable HttpModule to your website which allows on-the-fly processing of image files. The module also comes with a file and browser based cache that can handle millions of images, increasing your processing output and saving precious server memory. Methods include: Resize, Rotate, Rounded Corners, Flip, Crop, Watermark, Filter, Saturation, Brightness, Contrast, Quality, Format, Vignette, Gaussian Blur, Gaussian Sharpen, and Transparency. If you use ImageProcessor please get in touch via my twitter @james_m_south Feedback is always welcome - An extension to ImageProcessor that allows on-the-fly processing of image files in an ASP.NET website - - James South - en-GB - Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff ASP Cache EXIF - - - - - - - - - - + An extension to ImageProcessor that allows on-the-fly processing of image files in an ASP.NET website + + James South + en-GB + Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff ASP Cache EXIF + + + + + + + + + + \ No newline at end of file diff --git a/build/NuSpecs/ImageProcessor.nuspec b/build/NuSpecs/ImageProcessor.nuspec index 60c6df338..be9eedbb0 100644 --- a/build/NuSpecs/ImageProcessor.nuspec +++ b/build/NuSpecs/ImageProcessor.nuspec @@ -1,29 +1,29 @@  - - ImageProcessor - 2.1.0.0 - ImageProcessor - James South - James South - http://imageprocessor.org - http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png - false - Image Processor is an easy to use and extend processing library written in C#. Its fluent API makes common imaging tasks very simple to perform. + + ImageProcessor + 2.1.0.0 + ImageProcessor + James South + James South + http://imageprocessor.org + http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png + false + Image Processor is an easy to use and extend processing library written in C#. Its fluent API makes common imaging tasks very simple to perform. Methods include; Resize, Rotate, Rounded Corners, Flip, Crop, Watermark, Filter, Saturation, Brightness, Contrast, Quality, Format, Vignette, Gaussian Blur, Gaussian Sharpen, and Transparency. If you use ImageProcessor please get in touch on my twitter @james_m_south. Feedback is always welcome. - A library for manipulating image files written in C#. - - James South - en-GB - Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff Fluent Animated EXIF - - - - - + A library for manipulating image files written in C#. + + James South + en-GB + Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff Fluent Animated EXIF + + + + + \ No newline at end of file diff --git a/build/build.xml b/build/build.xml index 1e9190fe1..93173c744 100644 --- a/build/build.xml +++ b/build/build.xml @@ -13,7 +13,7 @@ ImageProcessor Web - 4.1.0.0 + 4.1.1.0 ..\src\ImageProcessor.Web ImageProcessor.Web.csproj diff --git a/src/ImageProcessor.Web/Configuration/ImageProcessorConfiguration.cs b/src/ImageProcessor.Web/Configuration/ImageProcessorConfiguration.cs index 46afcbc9c..69bc77b7a 100644 --- a/src/ImageProcessor.Web/Configuration/ImageProcessorConfiguration.cs +++ b/src/ImageProcessor.Web/Configuration/ImageProcessorConfiguration.cs @@ -348,12 +348,9 @@ namespace ImageProcessor.Web.Configuration IImageService imageService = Activator.CreateInstance(type) as IImageService; if (!string.IsNullOrWhiteSpace(config.Prefix)) { - if (!string.IsNullOrWhiteSpace(config.Prefix)) + if (imageService != null) { - if (imageService != null) - { - imageService.Prefix = config.Prefix; - } + imageService.Prefix = config.Prefix; } } diff --git a/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs b/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs index 67875b3e6..2f1c83291 100644 --- a/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs +++ b/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs @@ -280,11 +280,12 @@ namespace ImageProcessor.Web.HttpModules if (currentService != null) { bool isFileLocal = currentService.IsFileLocalService; + bool hasMultiParams = request.Url.ToString().Count(f => f == '?') > 1; string requestPath = string.Empty; string queryString = string.Empty; string urlParameters = string.Empty; - if (!isFileLocal) + if (hasMultiParams) { // We need to split the querystring to get the actual values we want. string urlDecode = HttpUtility.UrlDecode(request.QueryString.ToString()); @@ -376,9 +377,11 @@ namespace ImageProcessor.Web.HttpModules { byte[] imageBuffer; - if (!isFileLocal) + if (hasMultiParams) { - Uri uri = new Uri(requestPath + "?" + urlParameters); + Uri uri = string.IsNullOrWhiteSpace(urlParameters) + ? new Uri(requestPath, UriKind.RelativeOrAbsolute) + : new Uri(requestPath + "?" + urlParameters, UriKind.RelativeOrAbsolute); imageBuffer = await currentService.GetImage(uri); } else @@ -434,12 +437,21 @@ namespace ImageProcessor.Web.HttpModules if (isFileLocal) { - // Set the headers and quit. - this.SetHeaders(context, (string)context.Items[CachedResponseTypeKey], new List { requestPath, cachedPath }); - return; + // Set the headers and quit. + // Some services might only provide filename so we can't monitor for the browser. + this.SetHeaders( + context, + (string)context.Items[CachedResponseTypeKey], + Path.GetFileName(requestPath) == requestPath ? new List { cachedPath } : new List { requestPath, cachedPath }); + } + else + { + this.SetHeaders(context, (string)context.Items[CachedResponseTypeKey], new List { cachedPath }); } - this.SetHeaders(context, (string)context.Items[CachedResponseTypeKey], new List { cachedPath }); + // Complete the requests but don't abort the thread. + context.ApplicationInstance.CompleteRequest(); + return; } // The cached file is valid so just rewrite the path. @@ -450,11 +462,6 @@ namespace ImageProcessor.Web.HttpModules throw new HttpException(403, "Access denied"); } } - else if (!isFileLocal) - { - // Just re-point to the external url. - HttpContext.Current.Response.Redirect(requestPath); - } } } @@ -496,6 +503,9 @@ namespace ImageProcessor.Web.HttpModules cache.SetExpires(DateTime.Now.ToUniversalTime().AddDays(maxDays)); cache.SetMaxAge(new TimeSpan(maxDays, 0, 0, 0)); cache.SetRevalidation(HttpCacheRevalidation.AllCaches); + + context.Items[CachedResponseTypeKey] = null; + context.Items[CachedResponseFileDependency] = null; } /// diff --git a/src/ImageProcessor.Web/Properties/AssemblyInfo.cs b/src/ImageProcessor.Web/Properties/AssemblyInfo.cs index 0d662823c..ea365f0cf 100644 --- a/src/ImageProcessor.Web/Properties/AssemblyInfo.cs +++ b/src/ImageProcessor.Web/Properties/AssemblyInfo.cs @@ -40,5 +40,5 @@ using System.Runtime.InteropServices; // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("4.1.0.0")] -[assembly: AssemblyFileVersion("4.1.0.0")] +[assembly: AssemblyVersion("4.1.1.0")] +[assembly: AssemblyFileVersion("4.1.1.0")] diff --git a/src/TestWebsites/MVC/TestImageService.cs b/src/TestWebsites/MVC/TestImageService.cs new file mode 100644 index 000000000..de632dfff --- /dev/null +++ b/src/TestWebsites/MVC/TestImageService.cs @@ -0,0 +1,130 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// The test image service. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace Test_Website_NET45 +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Threading.Tasks; + using System.Web; + using System.Web.Hosting; + + using ImageProcessor.Web.Services; + + /// + /// The test image service. + /// + public class TestImageService : IImageService + { + /// + /// The prefix for the given implementation. + /// + private string prefix = "testprovider.axd"; + + /// + /// Gets or sets the prefix for the given implementation. + /// + /// This value is used as a prefix for any image requests that should use this service. + /// + /// + public string Prefix + { + get + { + return this.prefix; + } + + set + { + this.prefix = value; + } + } + + /// + /// Gets a value indicating whether the image service requests files from + /// the locally based file system. + /// + public bool IsFileLocalService + { + get + { + return true; + } + } + + /// + /// Gets or sets any additional settings required by the service. + /// + public Dictionary Settings { get; set; } + + /// + /// Gets or sets the white list of . + /// + public Uri[] WhiteList { get; set; } + + /// + /// Gets a value indicating whether the current request passes sanitizing rules. + /// + /// + /// The image path. + /// + /// + /// True if the request is valid; otherwise, False. + /// + public bool IsValidRequest(string path) + { + return true; + } + + /// + /// Gets the image using the given identifier. + /// + /// + /// The value identifying the image to fetch. + /// + /// + /// The array containing the image data. + /// + public async Task GetImage(object id) + { + const string AppData = "~/App_Data/images"; + string imageRoot = HostingEnvironment.MapPath(AppData); + + if (imageRoot == null) + { + throw new HttpException(404, "No root path found to serve " + id); + } + + // In this instance we are just processing a set path. + // If you are using the querystring params as a means of identifying the correct image + // then you can do something with it here. + string path = Path.Combine(imageRoot, id.ToString().Split(new[] { '&', '?' })[0]); + byte[] buffer; + + // Check to see if the file exists. + // ReSharper disable once AssignNullToNotNullAttribute + FileInfo fileInfo = new FileInfo(path); + + if (!fileInfo.Exists) + { + throw new HttpException(404, "Nothing found at " + id); + } + + using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true)) + { + buffer = new byte[file.Length]; + await file.ReadAsync(buffer, 0, (int)file.Length); + } + + return buffer; + } + } +} \ No newline at end of file diff --git a/src/TestWebsites/MVC/Test_Website_MVC.csproj b/src/TestWebsites/MVC/Test_Website_MVC.csproj index c195bf9ce..9075ef587 100644 --- a/src/TestWebsites/MVC/Test_Website_MVC.csproj +++ b/src/TestWebsites/MVC/Test_Website_MVC.csproj @@ -109,6 +109,7 @@ + Global.asax