Browse Source

Added configuration-less functionality.

Former-commit-id: 49868772e9cc35d73fd0c84c4985f06d42b70b03
af/merge-core
James South 12 years ago
parent
commit
d45bc2bfce
  1. 13
      src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj
  2. 25
      src/ImageProcessor.Web/NET45/Config/ImageCacheSection.cs
  3. 10
      src/ImageProcessor.Web/NET45/Config/ImageProcessingSection.cs
  4. 16
      src/ImageProcessor.Web/NET45/Config/ImageSecuritySection.cs
  5. 1
      src/ImageProcessor.Web/NET45/Config/Resources/cache.config
  6. 39
      src/ImageProcessor.Web/NET45/Config/Resources/processing.config
  7. 4
      src/ImageProcessor.Web/NET45/Config/Resources/security.config
  8. 56
      src/ImageProcessor.Web/NET45/Helpers/ResourceHelpers.cs
  9. 8
      src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj
  10. 15
      src/ImageProcessor/Processors/Resize.cs
  11. BIN
      src/Nuget/ImageProcessor.Web.Config.1.0.0.0.nupkg

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

@ -72,6 +72,7 @@
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Data" />
<Reference Include="System.XML" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\NET45\Caching\CachedImage.cs" />
@ -90,6 +91,9 @@
<Link>ImageHelpers.cs</Link>
</Compile>
<Compile Include="..\NET45\Helpers\RemoteFile.cs" />
<Compile Include="..\NET45\Helpers\ResourceHelpers.cs">
<Link>ResourceHelpers.cs</Link>
</Compile>
<Compile Include="..\NET45\Helpers\StartUp.cs">
<Link>StartUp.cs</Link>
</Compile>
@ -105,6 +109,15 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\NET45\Config\Resources\cache.config">
<Link>Config\Resources\cache.config</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\NET45\Config\Resources\processing.config">
<Link>Config\Resources\processing.config</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\NET45\Config\Resources\security.config">
<Link>Config\Resources\security.config</Link>
</EmbeddedResource>
<None Include="app.config">
<SubType>Designer</SubType>
</None>

25
src/ImageProcessor.Web/NET45/Config/ImageCacheSection.cs

@ -1,16 +1,22 @@
// -----------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ImageCacheSection.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// -----------------------------------------------------------------------
// <summary>
// Represents an image cache section within a configuration file.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Web.Config
{
#region Using
using System.Configuration;
using System.IO;
using System.Xml;
using ImageProcessor.Extensions;
using ImageProcessor.Web.Helpers;
#endregion
@ -24,7 +30,7 @@ namespace ImageProcessor.Web.Config
/// </summary>
/// <value>The name of the cache folder.</value>
[ConfigurationProperty("virtualPath", DefaultValue = "~/app_data/cache", IsRequired = true)]
[StringValidator(MinLength = 3, MaxLength = 200)]
[StringValidator(MinLength = 3, MaxLength = 256)]
public string VirtualPath
{
get
@ -45,7 +51,7 @@ namespace ImageProcessor.Web.Config
/// </summary>
/// <value>The maximum number of days to store an image in the cache.</value>
/// <remarks>Defaults to 28 if not set.</remarks>
[ConfigurationProperty("maxDays", DefaultValue = "28", IsRequired = false)]
[ConfigurationProperty("maxDays", DefaultValue = "365", IsRequired = false)]
[IntegerValidator(ExcludeRange = false, MinValue = 0)]
public int MaxDays
{
@ -73,7 +79,12 @@ namespace ImageProcessor.Web.Config
return imageCacheSection;
}
return new ImageCacheSection();
string section = ResourceHelpers.ResourceAsString("ImageProcessor.Web.Config.Resources.cache.config");
XmlReader reader = new XmlTextReader(new StringReader(section));
imageCacheSection = new ImageCacheSection();
imageCacheSection.DeserializeSection(reader);
return imageCacheSection;
}
}
}

10
src/ImageProcessor.Web/NET45/Config/ImageProcessingSection.cs

@ -13,7 +13,10 @@ namespace ImageProcessor.Web.Config
{
#region Using
using System.Configuration;
using System.IO;
using System.Linq;
using System.Xml;
using ImageProcessor.Web.Helpers;
#endregion
/// <summary>
@ -69,7 +72,12 @@ namespace ImageProcessor.Web.Config
return imageProcessingSection;
}
return new ImageProcessingSection();
string section = ResourceHelpers.ResourceAsString("ImageProcessor.Web.Config.Resources.processing.config");
XmlReader reader = new XmlTextReader(new StringReader(section));
imageProcessingSection = new ImageProcessingSection();
imageProcessingSection.DeserializeSection(reader);
return imageProcessingSection;
}
#endregion

16
src/ImageProcessor.Web/NET45/Config/ImageSecuritySection.cs

@ -13,6 +13,11 @@ namespace ImageProcessor.Web.Config
#region Using
using System;
using System.Configuration;
using System.IO;
using System.Xml;
using ImageProcessor.Web.Helpers;
#endregion
/// <summary>
@ -55,8 +60,8 @@ namespace ImageProcessor.Web.Config
/// Gets or sets the maximum allowed remote file size in bytes for the application.
/// </summary>
/// <value>The maximum number of days to store an image in the cache.</value>
/// <remarks>Defaults to 524288 (512kb) if not set.</remarks>
[ConfigurationProperty("maxBytes", DefaultValue = "524288", IsRequired = true)]
/// <remarks>Defaults to 4194304 (4Mb) if not set.</remarks>
[ConfigurationProperty("maxBytes", DefaultValue = "4194304", IsRequired = true)]
public int MaxBytes
{
get
@ -111,7 +116,12 @@ namespace ImageProcessor.Web.Config
return imageSecuritySection;
}
return new ImageSecuritySection();
string section = ResourceHelpers.ResourceAsString("ImageProcessor.Web.Config.Resources.security.config");
XmlReader reader = new XmlTextReader(new StringReader(section));
imageSecuritySection = new ImageSecuritySection();
imageSecuritySection.DeserializeSection(reader);
return imageSecuritySection;
}
#endregion

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

@ -0,0 +1 @@
<cache virtualPath="~/app_data/cache" maxDays="356"/>

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

@ -0,0 +1,39 @@
<processing>
<presets>
</presets>
<plugins autoLoadPlugins="true">
<plugin name="Alpha" type="ImageProcessor.Processors.Alpha, 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"/>
<plugin name="Filter" type="ImageProcessor.Processors.Filter, ImageProcessor"/>
<plugin name="Flip" type="ImageProcessor.Processors.Flip, ImageProcessor"/>
<plugin name="Format" type="ImageProcessor.Processors.Format, ImageProcessor"/>
<plugin name="GaussianBlur" type="ImageProcessor.Processors.GaussianBlur, ImageProcessor">
<settings>
<setting key="MaxSize" value="22"/>
<setting key="MaxSigma" value="5.1"/>
<setting key="MaxThreshold" value="100"/>
</settings>
</plugin>
<plugin name="GaussianSharpen" type="ImageProcessor.Processors.GaussianSharpen, ImageProcessor">
<settings>
<setting key="MaxSize" value="22"/>
<setting key="MaxSigma" value="5.1"/>
<setting key="MaxThreshold" value="100"/>
</settings>
</plugin>
<plugin name="Quality" type="ImageProcessor.Processors.Quality, ImageProcessor"/>
<plugin name="Resize" type="ImageProcessor.Processors.Resize, ImageProcessor">
<settings>
<setting key="MaxWidth" value="5000"/>
<setting key="MaxHeight" value="5000"/>
</settings>
</plugin>
<plugin name="Rotate" type="ImageProcessor.Processors.Rotate, ImageProcessor"/>
<plugin name="RoundedCorners" type="ImageProcessor.Processors.RoundedCorners, ImageProcessor"/>
<plugin name="Saturation" type="ImageProcessor.Processors.Saturation, ImageProcessor"/>
<plugin name="Vignette" type="ImageProcessor.Processors.Vignette, ImageProcessor"/>
<plugin name="Watermark" type="ImageProcessor.Processors.Watermark, ImageProcessor"/>
</plugins>
</processing>

4
src/ImageProcessor.Web/NET45/Config/Resources/security.config

@ -0,0 +1,4 @@
<security allowRemoteDownloads="true" timeout="300000" maxBytes="4194304" remotePrefix="/remote.axd">
<whiteList>
</whiteList>
</security>

56
src/ImageProcessor.Web/NET45/Helpers/ResourceHelpers.cs

@ -0,0 +1,56 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ResourceHelpers.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// <summary>
// Provides helper methods for working with resources.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Web.Helpers
{
using System.IO;
using System.Reflection;
using System.Text;
/// <summary>
/// Provides helper methods for working with resources.
/// </summary>
public class ResourceHelpers
{
/// <summary>
/// Converts an assembly resource into a string.
/// </summary>
/// <param name="resource">
/// The resource.
/// </param>
/// <param name="assembly">
/// The assembly.
/// </param>
/// <param name="encoding">
/// The character encoding to return the resource in.
/// </param>
/// <returns>
/// The <see cref="string"/>.
/// </returns>
public static string ResourceAsString(string resource, Assembly assembly = null, Encoding encoding = null)
{
assembly = assembly ?? Assembly.GetExecutingAssembly();
encoding = encoding ?? Encoding.UTF8;
using (MemoryStream ms = new MemoryStream())
{
using (Stream manifestResourceStream = assembly.GetManifestResourceStream(resource))
{
if (manifestResourceStream != null)
{
manifestResourceStream.CopyTo(ms);
}
}
return encoding.GetString(ms.GetBuffer()).Replace('\0', ' ').Trim();
}
}
}
}

8
src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj

@ -57,6 +57,7 @@
<Compile Include="Config\ImageProcessingSection.cs" />
<Compile Include="Config\ImageProcessorConfig.cs" />
<Compile Include="Config\ImageSecuritySection.cs" />
<Compile Include="Helpers\ResourceHelpers.cs" />
<Compile Include="Helpers\StartUp.cs" />
<Compile Include="Helpers\ImageHelpers.cs" />
<Compile Include="Helpers\RemoteFile.cs" />
@ -72,6 +73,13 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Config\Resources\cache.config">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Config\Resources\processing.config">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Config\Resources\security.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

15
src/ImageProcessor/Processors/Resize.cs

@ -446,12 +446,19 @@ namespace ImageProcessor.Processors
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.CompositingMode = CompositingMode.SourceCopy;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.Clear(backgroundColor);
Rectangle destRect = new Rectangle(destinationX, destinationY, destinationWidth, destinationHeight);
graphics.DrawImage(image, destRect, 0, 0, sourceWidth, sourceHeight, GraphicsUnit.Pixel);
// An unwanted border appears when using InterpolationMode.HighQualityBicubic to resize the image
// as the algorithm appears to be pulling averaging detail from surrounding pixels beyond the edge
// of the image. Using the ImageAttributes class to specify that the pixels beyond are simply mirror
// images of the pixels within solves this problem.
using (ImageAttributes wrapMode = new ImageAttributes())
{
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
graphics.Clear(backgroundColor);
Rectangle destRect = new Rectangle(destinationX, destinationY, destinationWidth, destinationHeight);
graphics.DrawImage(image, destRect, 0, 0, sourceWidth, sourceHeight, GraphicsUnit.Pixel, wrapMode);
}
// Reassign the image.
image.Dispose();

BIN
src/Nuget/ImageProcessor.Web.Config.1.0.0.0.nupkg

Binary file not shown.
Loading…
Cancel
Save