Browse Source

Merge remote-tracking branch 'origin/dev'

Former-commit-id: 6b30c148c0550a3c78b82d8d810490beaed3859e
af/merge-core
James South 12 years ago
parent
commit
b7e9846802
  1. 6
      build/Build.bat
  2. 8
      build/NuSpecs/ImageProcessor.Web.Config.nuspec
  3. 8
      build/NuSpecs/ImageProcessor.Web.nuspec
  4. 2
      build/NuSpecs/ImageProcessor.nuspec
  5. 7
      src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj
  6. 4
      src/ImageProcessor.Web/NET4/app.config
  7. 2
      src/ImageProcessor.Web/NET4/packages.config
  8. 3
      src/ImageProcessor.Web/NET45/Caching/CacheIndexer.cs
  9. 5
      src/ImageProcessor.Web/NET45/Caching/CachedImage.cs
  10. 161
      src/ImageProcessor.Web/NET45/Caching/DiskCache.cs
  11. 1
      src/ImageProcessor.Web/NET45/Config/Resources/processing.config
  12. 10
      src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs
  13. 4
      src/ImageProcessor.Web/NET45/Properties/AssemblyInfo.cs
  14. 93
      src/ImageProcessor/ImageFactory.cs
  15. 1
      src/ImageProcessor/ImageProcessor.csproj
  16. 158
      src/ImageProcessor/Processors/AutoRotate.cs
  17. 4
      src/ImageProcessor/Properties/AssemblyInfo.cs
  18. 1
      src/Images/rotate.jpg.REMOVED.git-id
  19. 6
      src/TestWebsites/NET4/Test_Website_MVC_NET4.csproj
  20. 10
      src/TestWebsites/NET4/Web.config
  21. 1
      src/TestWebsites/NET4/config/imageprocessor/processing.config
  22. 2
      src/TestWebsites/NET4/packages.config

6
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%

8
build/NuSpecs/ImageProcessor.Web.Config.nuspec

@ -21,12 +21,12 @@ Feedback is always welcome</description>
<tags>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</tags>
<dependencies>
<group targetFramework=".NETFramework4.0">
<dependency id="ImageProcessor" version="1.9.2.0" />
<dependency id="ImageProcessor.Web" version="3.2.5.0" />
<dependency id="ImageProcessor" version="1.9.3.0" />
<dependency id="ImageProcessor.Web" version="3.2.7.0" />
</group>
<group targetFramework=".NETFramework4.5">
<dependency id="ImageProcessor" version="1.9.2.0" />
<dependency id="ImageProcessor.Web" version="3.2.5.0" />
<dependency id="ImageProcessor" version="1.9.3.0" />
<dependency id="ImageProcessor.Web" version="3.2.7.0" />
</group>
</dependencies>
</metadata>

8
build/NuSpecs/ImageProcessor.Web.nuspec

@ -22,15 +22,15 @@ Feedback is always welcome</description>
<releaseNotes />
<copyright>James South</copyright>
<language>en-GB</language>
<tags>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</tags>
<tags>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</tags>
<dependencies>
<group targetFramework=".NETFramework4.0">
<dependency id="Microsoft.Bcl.Async" version="1.0.168" />
<dependency id="Microsoft.Bcl" version="1.1.8" />
<dependency id="ImageProcessor" version="1.9.2.0" />
<dependency id="Microsoft.Bcl" version="1.1.9" />
<dependency id="ImageProcessor" version="1.9.3.0" />
</group>
<group targetFramework=".NETFramework4.5">
<dependency id="ImageProcessor" version="1.9.2.0" />
<dependency id="ImageProcessor" version="1.9.3.0" />
</group>
</dependencies>
</metadata>

2
build/NuSpecs/ImageProcessor.nuspec

@ -21,7 +21,7 @@ Feedback is always welcome.</description>
<releaseNotes />
<copyright>James South</copyright>
<language>en-GB</language>
<tags>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</tags>
<tags>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</tags>
</metadata>
<files>
<file src="..\_BuildOutput\ImageProcessor\lib\ImageProcessor.dll" target="lib\ImageProcessor.dll" />

7
src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj

@ -59,15 +59,16 @@
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.IO">
<HintPath>..\..\packages\Microsoft.Bcl.1.1.8\lib\net40\System.IO.dll</HintPath>
<HintPath>..\..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.IO.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net" />
<Reference Include="System.Runtime">
<HintPath>..\..\packages\Microsoft.Bcl.1.1.8\lib\net40\System.Runtime.dll</HintPath>
<HintPath>..\..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.Runtime.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Caching" />
<Reference Include="System.Threading.Tasks">
<HintPath>..\..\packages\Microsoft.Bcl.1.1.8\lib\net40\System.Threading.Tasks.dll</HintPath>
<HintPath>..\..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.Threading.Tasks.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Data" />

4
src/ImageProcessor.Web/NET4/app.config

@ -4,11 +4,11 @@
<assemblyBinding xmlns:bcl="urn:schemas-microsoft-com:bcl" xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly bcl:name="System.Runtime">
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.8.0" newVersion="2.6.8.0" />
<bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
</dependentAssembly>
<dependentAssembly bcl:name="System.Threading.Tasks">
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.8.0" newVersion="2.6.8.0" />
<bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>

2
src/ImageProcessor.Web/NET4/packages.config

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bcl" version="1.1.8" targetFramework="net40" />
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net40" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net40" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net40" />
</packages>

3
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
};
}
}

5
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.
/// </summary>
public DateTime CreationTimeUtc { get; set; }
/// <summary>
/// Gets or sets the last write time of the cached image.
/// </summary>
public DateTime LastWriteTimeUtc { get; set; }
}
}

161
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
/// <summary>
/// The absolute path to virtual cache path on the server.
/// </summary>
private static readonly string AbsoluteCachePath =
HostingEnvironment.MapPath(ImageProcessorConfig.Instance.VirtualCachePath);
private static readonly string AbsoluteCachePath = HostingEnvironment.MapPath(ImageProcessorConfig.Instance.VirtualCachePath);
/// <summary>
/// The request for the image.
@ -142,18 +140,14 @@ namespace ImageProcessor.Web.Caching
/// <summary>
/// Adds an image to the cache.
/// </summary>
/// <param name="creationAndLastWriteDateTimes">
/// The creation and last write times.
/// </param>
internal void AddImageToCache(Tuple<DateTime, DateTime> 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;
}
/// <summary>
/// Gets the <see cref="T:System.DateTime"/> set to the last write time of the file.
/// </summary>
/// <returns>
/// The last write time of the file.
/// </returns>
internal async Task<DateTime> GetLastWriteTimeAsync()
{
DateTime dateTime = DateTime.UtcNow;
CachedImage cachedImage = await CacheIndexer.GetValueAsync(this.CachedPath);
if (cachedImage != null)
{
dateTime = cachedImage.LastWriteTimeUtc;
}
return dateTime;
}
/// <summary>
/// Sets the LastWriteTime of the cached file to match the original file.
/// </summary>
/// <returns>
/// The <see cref="T:System.DateTime"/> set to the last write time of the file.
/// </returns>
internal async Task<Tuple<DateTime, DateTime>> SetCachedLastWriteTimeAsync()
{
// Create Action delegate for SetCachedLastWriteTime.
return await TaskHelpers.Run(() => this.SetCachedLastWriteTime());
}
/// <summary>
/// Trims a cached folder ensuring that it does not exceed the maximum file count.
/// </summary>
@ -273,46 +216,6 @@ namespace ImageProcessor.Web.Caching
#endregion
#region Private
/// <summary>
/// Sets the LastWriteTime of the cached file to match the original file.
/// </summary>
/// <returns>
/// The <see cref="T:System.DateTime"/> of the original and cached file.
/// </returns>
private Tuple<DateTime, DateTime> 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<DateTime, DateTime>(creationTime, lastWriteTime);
}
/// <summary>
/// Trims a cached folder ensuring that it does not exceed the maximum file count.
/// </summary>
@ -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;
}
/// <summary>
/// The rough date time compare.
/// </summary>
/// <param name="first">
/// The first.
/// </param>
/// <param name="second">
/// The second.
/// </param>
/// <returns>
/// The <see cref="bool"/> true if the DateTimes roughly compare; otherwise, false.
/// </returns>
private bool RoughDateTimeCompare(DateTime first, DateTime second)
{
if (first.ToString(CultureInfo.InvariantCulture) == second.ToString(CultureInfo.InvariantCulture))
{
return true;
}
return false;
}
/// <summary>
/// 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
}
}
}

1
src/ImageProcessor.Web/NET45/Config/Resources/processing.config

@ -3,6 +3,7 @@
</presets>
<plugins autoLoadPlugins="true">
<plugin name="Alpha" type="ImageProcessor.Processors.Alpha, ImageProcessor"/>
<plugin name="AutoRotate" type="ImageProcessor.Processors.AutoRotate, ImageProcessor"/>
<plugin name="Brightness" type="ImageProcessor.Processors.Brightness, ImageProcessor"/>
<plugin name="Contrast" type="ImageProcessor.Processors.Contrast, ImageProcessor"/>
<plugin name="Crop" type="ImageProcessor.Processors.Crop, ImageProcessor"/>

10
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<DateTime, DateTime> 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<DateTime, DateTime> creationAndLastWriteDateTimes = await cache.SetCachedLastWriteTimeAsync();
// Add to the cache.
cache.AddImageToCache(creationAndLastWriteDateTimes);
cache.AddImageToCache();
// Trim the cache.
await cache.TrimCachedFolderAsync(cachedPath);

4
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")]
[assembly: AssemblyVersion("3.2.7.0")]
[assembly: AssemblyFileVersion("3.2.7.0")]

93
src/ImageProcessor/ImageFactory.cs

@ -182,12 +182,10 @@ namespace ImageProcessor
this.backupImageFormat = this.ImageFormat;
this.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;
@ -244,12 +242,10 @@ namespace ImageProcessor
this.ImageFormat = imageFormat;
this.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;
@ -347,6 +343,24 @@ namespace ImageProcessor
return this;
}
/// <summary>
/// Performs auto-rotation to ensure that EXIF defined rotation is reflected in
/// the final image.
/// </summary>
/// <returns>
/// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
/// </returns>
public ImageFactory AutoRotate()
{
if (this.ShouldProcess)
{
AutoRotate autoRotate = new AutoRotate();
this.ApplyProcessor(autoRotate.ProcessImage);
}
return this;
}
/// <summary>
/// Changes the brightness of the current image.
/// </summary>
@ -435,7 +449,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);
}
@ -868,6 +882,25 @@ namespace ImageProcessor
// Fix the colour palette of indexed images.
this.FixIndexedPallete();
// Set the property item information from any Exif metadata.
// We do this here so that they can be changed between processor methods.
if (this.PreserveExifData)
{
foreach (KeyValuePair<int, PropertyItem> propertItem in this.ExifPropertyItems)
{
try
{
this.Image.SetPropertyItem(propertItem.Value);
}
// ReSharper disable once EmptyGeneralCatchClause
catch
{
// Do nothing. The image format does not handle EXIF data.
// TODO: empty catch is fierce code smell.
}
}
}
// ReSharper disable once AssignNullToNotNullAttribute
DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(filePath));
@ -944,6 +977,25 @@ namespace ImageProcessor
// Fix the colour palette of gif and png8 images.
this.FixIndexedPallete();
// Set the property item information from any Exif metadata.
// We do this here so that they can be changed between processor methods.
if (this.PreserveExifData)
{
foreach (KeyValuePair<int, PropertyItem> propertItem in this.ExifPropertyItems)
{
try
{
this.Image.SetPropertyItem(propertItem.Value);
}
// ReSharper disable once EmptyGeneralCatchClause
catch
{
// Do nothing. The image format does not handle EXIF data.
// TODO: empty catch is fierce code smell.
}
}
}
if (this.ImageFormat.Equals(ImageFormat.Jpeg))
{
// Jpegs can be saved with different settings to include a quality setting for the JPEG compression.
@ -1074,25 +1126,6 @@ namespace ImageProcessor
{
this.Image = processor.Invoke(this);
}
// Set the property item information from any Exif metadata.
// We do this here so that they can be changed between processor methods.
if (this.PreserveExifData)
{
foreach (KeyValuePair<int, PropertyItem> propertItem in this.ExifPropertyItems)
{
try
{
this.Image.SetPropertyItem(propertItem.Value);
}
// ReSharper disable once EmptyGeneralCatchClause
catch
{
// Do nothing. The image format does not handle EXIF data.
// TODO: empty catch is fierce code smell.
}
}
}
}
#endregion
}

1
src/ImageProcessor/ImageProcessor.csproj

@ -100,6 +100,7 @@
<Compile Include="Imaging\TextLayer.cs" />
<Compile Include="Imaging\OctreeQuantizer.cs" />
<Compile Include="Processors\Alpha.cs" />
<Compile Include="Processors\AutoRotate.cs" />
<Compile Include="Processors\GaussianBlur.cs" />
<Compile Include="Processors\Brightness.cs" />
<Compile Include="Processors\Contrast.cs" />

158
src/ImageProcessor/Processors/AutoRotate.cs

@ -0,0 +1,158 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AutoRotate.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// <summary>
// Performs auto-rotation to ensure that EXIF defined rotation is reflected in
// the final image.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Processors
{
using System.Collections.Generic;
using System.Drawing;
using System.Text.RegularExpressions;
using ImageProcessor.Imaging;
/// <summary>
/// Performs auto-rotation to ensure that EXIF defined rotation is reflected in
/// the final image.
/// </summary>
public class AutoRotate : IGraphicsProcessor
{
/// <summary>
/// The regular expression to search strings for.
/// </summary>
private static readonly Regex QueryRegex = new Regex(@"autorotate=true", RegexOptions.Compiled);
/// <summary>
/// Gets the regular expression to search strings for.
/// </summary>
public Regex RegexPattern
{
get
{
return QueryRegex;
}
}
/// <summary>
/// Gets or sets DynamicParameter.
/// </summary>
public dynamic DynamicParameter
{
get;
set;
}
/// <summary>
/// Gets the order in which this processor is to be used in a chain.
/// </summary>
public int SortOrder
{
get;
private set;
}
/// <summary>
/// Gets or sets any additional settings required by the processor.
/// </summary>
public Dictionary<string, string> Settings
{
get;
set;
}
/// <summary>
/// The position in the original string where the first character of the captured substring was found.
/// </summary>
/// <param name="queryString">
/// The query string to search.
/// </param>
/// <returns>
/// The zero-based starting position in the original string where the captured substring was found.
/// </returns>
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;
}
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="factory">The the current instance of the
/// <see cref="T:ImageProcessor.ImageFactory" /> class containing
/// the image to process.</param>
/// <returns>
/// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory" /> class.
/// </returns>
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;
}
}
}

4
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")]

1
src/Images/rotate.jpg.REMOVED.git-id

@ -0,0 +1 @@
406a6a7916628c0c0bea8243565a7162ebd5a505

6
src/TestWebsites/NET4/Test_Website_MVC_NET4.csproj

@ -70,14 +70,14 @@
</Reference>
<Reference Include="System.Data.Entity" />
<Reference Include="System.IO">
<HintPath>..\..\packages\Microsoft.Bcl.1.1.8\lib\net40\System.IO.dll</HintPath>
<HintPath>..\..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.IO.dll</HintPath>
</Reference>
<Reference Include="System.Net" />
<Reference Include="System.Runtime">
<HintPath>..\..\packages\Microsoft.Bcl.1.1.8\lib\net40\System.Runtime.dll</HintPath>
<HintPath>..\..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.Runtime.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks">
<HintPath>..\..\packages\Microsoft.Bcl.1.1.8\lib\net40\System.Threading.Tasks.dll</HintPath>
<HintPath>..\..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.Threading.Tasks.dll</HintPath>
</Reference>
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

10
src/TestWebsites/NET4/Web.config

@ -46,7 +46,7 @@
</namespaces>
</pages>
<httpModules>
<add name="ImageProcessorModule" type="ImageProcessor.Web.HttpModules.ImageProcessingModule, ImageProcessor.Web"/>
<add name="ImageProcessorModule" type="ImageProcessor.Web.HttpModules.ImageProcessingModule, ImageProcessor.Web" />
</httpModules>
<!--Set the trust level.-->
<!--<trust level="Medium"/>-->
@ -63,13 +63,13 @@
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<dependentAssembly name="System.Runtime">
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.8.0" newVersion="2.6.8.0" />
<bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
</dependentAssembly>
<dependentAssembly>
<dependentAssembly name="System.Threading.Tasks">
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.8.0" newVersion="2.6.8.0" />
<bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>

1
src/TestWebsites/NET4/config/imageprocessor/processing.config

@ -5,6 +5,7 @@
</presets>
<plugins autoLoadPlugins="true">
<plugin name="Alpha" type="ImageProcessor.Processors.Alpha, ImageProcessor"/>
<plugin name="AutoRotate" type="ImageProcessor.Processors.AutoRotate, ImageProcessor"/>
<plugin name="Brightness" type="ImageProcessor.Processors.Brightness, ImageProcessor"/>
<plugin name="Contrast" type="ImageProcessor.Processors.Contrast, ImageProcessor"/>
<plugin name="Crop" type="ImageProcessor.Processors.Crop, ImageProcessor"/>

2
src/TestWebsites/NET4/packages.config

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bcl" version="1.1.8" targetFramework="net40" />
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net40" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net40" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net40" />
</packages>
Loading…
Cancel
Save