diff --git a/src/ImageProcessor.Web/NET45/Helpers/ImageHelpers.cs b/src/ImageProcessor.Web/NET45/Helpers/ImageHelpers.cs
index c08a60bea2..c5000851ec 100644
--- a/src/ImageProcessor.Web/NET45/Helpers/ImageHelpers.cs
+++ b/src/ImageProcessor.Web/NET45/Helpers/ImageHelpers.cs
@@ -11,8 +11,6 @@
namespace ImageProcessor.Web.Helpers
{
#region Using
- using System.Drawing.Imaging;
- using System.IO;
using System.Text.RegularExpressions;
#endregion
@@ -53,44 +51,7 @@ namespace ImageProcessor.Web.Helpers
public static string GetExtension(string input)
{
Match match = FormatRegex.Matches(input)[0];
-
return match.Success ? match.Value : string.Empty;
}
-
- ///
- /// Returns the correct image format based on the given file extension.
- ///
- /// The string containing the filename to check against.
- /// The correct image format based on the given filename.
- //public static ImageFormat GetImageFormat(string fileName)
- //{
- // string extension = Path.GetExtension(fileName);
-
- // if (extension != null)
- // {
- // string ext = extension.ToUpperInvariant();
-
- // switch (ext)
- // {
- // case ".ICO":
- // return ImageFormat.Icon;
- // case ".PNG":
- // return ImageFormat.Png;
- // case ".BMP":
- // return ImageFormat.Bmp;
- // case ".GIF":
- // return ImageFormat.Gif;
- // case ".TIF":
- // case ".TIFF":
- // return ImageFormat.Tiff;
- // default:
- // // Should be a jpeg.
- // return ImageFormat.Jpeg;
- // }
- // }
-
- // // TODO: Show custom exception?
- // return null;
- //}
}
}
diff --git a/src/ImageProcessor/Extensions/DoubleExtensions.cs b/src/ImageProcessor/Extensions/DoubleExtensions.cs
new file mode 100644
index 0000000000..a21817df14
--- /dev/null
+++ b/src/ImageProcessor/Extensions/DoubleExtensions.cs
@@ -0,0 +1,36 @@
+// --------------------------------------------------------------------------------------------------------------------
+//
+// Copyright (c) James South.
+// Licensed under the Apache License, Version 2.0.
+//
+//
+// Encapsulates a series of time saving extension methods to the class.
+//
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace ImageProcessor.Extensions
+{
+ ///
+ /// Encapsulates a series of time saving extension methods to the class.
+ ///
+ public static class DoubleExtensions
+ {
+ ///
+ /// Converts an value into a valid .
+ ///
+ /// If the value given is less than 0 or greater than 255, the value will be constrained into
+ /// those restricted ranges.
+ ///
+ ///
+ ///
+ /// The to convert.
+ ///
+ ///
+ /// The .
+ ///
+ public static byte ToByte(this double d)
+ {
+ return (byte)((d > byte.MaxValue) ? byte.MaxValue : ((d < byte.MinValue) ? byte.MinValue : d));
+ }
+ }
+}
diff --git a/src/ImageProcessor/Extensions/IntegerExtensions.cs b/src/ImageProcessor/Extensions/IntegerExtensions.cs
new file mode 100644
index 0000000000..a247d65110
--- /dev/null
+++ b/src/ImageProcessor/Extensions/IntegerExtensions.cs
@@ -0,0 +1,36 @@
+// --------------------------------------------------------------------------------------------------------------------
+//
+// Copyright (c) James South.
+// Licensed under the Apache License, Version 2.0.
+//
+//
+// Encapsulates a series of time saving extension methods to the class.
+//
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace ImageProcessor.Extensions
+{
+ ///
+ /// Encapsulates a series of time saving extension methods to the class.
+ ///
+ public static class IntegerExtensions
+ {
+ ///
+ /// Converts an value into a valid .
+ ///
+ /// If the value given is less than 0 or greater than 255, the value will be constrained into
+ /// those restricted ranges.
+ ///
+ ///
+ ///
+ /// The to convert.
+ ///
+ ///
+ /// The .
+ ///
+ public static byte ToByte(this int integer)
+ {
+ return ((double)integer).ToByte();
+ }
+ }
+}
diff --git a/src/ImageProcessor/ImageProcessor.csproj b/src/ImageProcessor/ImageProcessor.csproj
index 0acdba19ff..5a5b7c98e6 100644
--- a/src/ImageProcessor/ImageProcessor.csproj
+++ b/src/ImageProcessor/ImageProcessor.csproj
@@ -59,8 +59,9 @@
-
+
+
diff --git a/src/ImageProcessor/Imaging/ColorQuantizer.cs b/src/ImageProcessor/Imaging/ColorQuantizer.cs
index 932da35090..004e1bc351 100644
--- a/src/ImageProcessor/Imaging/ColorQuantizer.cs
+++ b/src/ImageProcessor/Imaging/ColorQuantizer.cs
@@ -56,7 +56,7 @@ namespace ImageProcessor.Imaging
int height = image.Height;
Rectangle sourceRect = Rectangle.FromLTRB(0, 0, width, height);
- // create a 24-bit rgb version of the source image
+ // Create a 24-bit rgb version of the source image
using (Bitmap bitmapSource = new Bitmap(width, height, PixelFormat.Format32bppArgb))
{
using (Graphics grfx = Graphics.FromImage(bitmapSource))
diff --git a/src/ImageProcessor/Imaging/Convolution.cs b/src/ImageProcessor/Imaging/Convolution.cs
index 5e8aac4332..7663188e3a 100644
--- a/src/ImageProcessor/Imaging/Convolution.cs
+++ b/src/ImageProcessor/Imaging/Convolution.cs
@@ -14,6 +14,7 @@ namespace ImageProcessor.Imaging
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
+ using ImageProcessor.Extensions;
///
/// Provides methods for applying blurring and sharpening effects to an image..
@@ -383,10 +384,10 @@ namespace ImageProcessor.Imaging
blue += this.Threshold;
alpha += this.Threshold;
- resultBuffer[byteOffset] = (byte)((blue > 255) ? 255 : ((blue < 0) ? 0 : blue));
- resultBuffer[byteOffset + 1] = (byte)((green > 255) ? 255 : ((green < 0) ? 0 : green));
- resultBuffer[byteOffset + 2] = (byte)((red > 255) ? 255 : ((red < 0) ? 0 : red));
- resultBuffer[byteOffset + 3] = (byte)((alpha > 255) ? 255 : ((alpha < 0) ? 0 : alpha));
+ resultBuffer[byteOffset] = blue.ToByte(); // (byte)((blue > 255) ? 255 : ((blue < 0) ? 0 : blue));
+ resultBuffer[byteOffset + 1] = green.ToByte(); // (byte)((green > 255) ? 255 : ((green < 0) ? 0 : green));
+ resultBuffer[byteOffset + 2] = red.ToByte(); // (byte)((red > 255) ? 255 : ((red < 0) ? 0 : red));
+ resultBuffer[byteOffset + 3] = alpha.ToByte(); // (byte)((alpha > 255) ? 255 : ((alpha < 0) ? 0 : alpha));
}
}
diff --git a/src/ImageProcessor/Imaging/Filters/ComicMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/ComicMatrixFilter.cs
index 08d0e66318..408a4b6e54 100644
--- a/src/ImageProcessor/Imaging/Filters/ComicMatrixFilter.cs
+++ b/src/ImageProcessor/Imaging/Filters/ComicMatrixFilter.cs
@@ -17,6 +17,9 @@ namespace ImageProcessor.Imaging.Filters
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
+
+ using ImageProcessor.Extensions;
+
#endregion
///
@@ -307,14 +310,10 @@ namespace ImageProcessor.Imaging.Filters
double green = Math.Abs(greenBin[maxIndex] / maxIntensity);
double red = Math.Abs(redBin[maxIndex] / maxIntensity);
- blue = blue > 255 ? 255 : (blue < 0 ? 0 : blue);
- green = green > 255 ? 255 : (green < 0 ? 0 : green);
- red = red > 255 ? 255 : (red < 0 ? 0 : red);
-
- resultBuffer[byteOffset] = (byte)blue;
- resultBuffer[byteOffset + 1] = (byte)green;
- resultBuffer[byteOffset + 2] = (byte)red;
- resultBuffer[byteOffset + 3] = 255;
+ resultBuffer[byteOffset] = blue.ToByte();
+ resultBuffer[byteOffset + 1] = green.ToByte();
+ resultBuffer[byteOffset + 2] = red.ToByte();
+ resultBuffer[byteOffset + 3] = pixelBuffer[byteOffset + 3];
}
}
@@ -333,7 +332,7 @@ namespace ImageProcessor.Imaging.Filters
///
/// Detects and draws edges.
- /// TODO: Move this to another class and do move edge detection.
+ /// TODO: Move this to another class and do edge detection.
///
///
/// The source bitmap.
@@ -494,7 +493,7 @@ namespace ImageProcessor.Imaging.Filters
}
else
{
- // These would normally be used to transfer the correct value accross.
+ // These would normally be used to transfer the correct value across.
// blue = pixelBuffer[byteOffset];
// green = pixelBuffer[byteOffset + 1];
// red = pixelBuffer[byteOffset + 2];
@@ -581,7 +580,11 @@ namespace ImageProcessor.Imaging.Filters
for (int i = rectangle.Height * rectangle.Width; i > 0; i--)
{
// Copy the alpha values across.
- destinationRgbValues[d] = sourceRgbValues[s];
+ if (destinationRgbValues[d] != 0)
+ {
+ destinationRgbValues[d] = sourceRgbValues[s];
+ }
+
d += 4;
s += 4;
}
diff --git a/src/ImageProcessor/Processors/Resize.cs b/src/ImageProcessor/Processors/Resize.cs
index 85cbd93500..9cb1fbc5ad 100644
--- a/src/ImageProcessor/Processors/Resize.cs
+++ b/src/ImageProcessor/Processors/Resize.cs
@@ -33,7 +33,7 @@ namespace ImageProcessor.Processors
///
/// The regular expression to search strings for.
///
- private static readonly Regex QueryRegex = new Regex(@"((width|height)=\d+)|(mode=(pad|stretch|crop|max))|(anchor=(top|bottom|left|right|center))|(bgcolor=([0-9a-fA-F]{3}){1,2})|(upscale=false)", RegexOptions.Compiled);
+ private static readonly Regex QueryRegex = new Regex(@"((width|height)=\d+)|(mode=(pad|stretch|crop|max))|(anchor=(top|bottom|left|right|center))|(bgcolor=(transparent|\d+,\d+,\d+,\d+|([0-9a-fA-F]{3}){1,2}))|(upscale=false)", RegexOptions.Compiled);
///
/// The regular expression to search strings for the size attribute.
@@ -53,7 +53,7 @@ namespace ImageProcessor.Processors
///
/// The regular expression to search strings for the color attribute.
///
- private static readonly Regex ColorRegex = new Regex(@"bgcolor=([0-9a-fA-F]{3}){1,2}", RegexOptions.Compiled);
+ private static readonly Regex ColorRegex = new Regex(@"bgcolor=(transparent|\d+,\d+,\d+,\d+|([0-9a-fA-F]{3}){1,2})", RegexOptions.Compiled);
///
/// The regular expression to search strings for the upscale attribute.
@@ -530,8 +530,26 @@ namespace ImageProcessor.Processors
{
foreach (Match match in ColorRegex.Matches(input))
{
+ string value = match.Value.Split('=')[1];
+
+ if (value == "transparent")
+ {
+ return Color.Transparent;
+ }
+
+ if (value.Contains(","))
+ {
+ int[] split = value.ToPositiveIntegerArray();
+ byte red = split[0].ToByte();
+ byte green = split[1].ToByte();
+ byte blue = split[2].ToByte();
+ byte alpha = split[3].ToByte();
+
+ return Color.FromArgb(alpha, red, green, blue);
+ }
+
// Split on color-hex
- return ColorTranslator.FromHtml("#" + match.Value.Split('=')[1]);
+ return ColorTranslator.FromHtml("#" + value);
}
return Color.Transparent;
diff --git a/src/TestWebsites/NET45/Test_Website_NET45/Images/circle.png b/src/TestWebsites/NET45/Test_Website_NET45/Images/circle.png
new file mode 100644
index 0000000000..3d96cf303b
--- /dev/null
+++ b/src/TestWebsites/NET45/Test_Website_NET45/Images/circle.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:3df296a3fd58930899d308558b128db760879cb776afba8f2d6511aba3934dd0
+size 6957
diff --git a/src/TestWebsites/NET45/Test_Website_NET45/Web.config b/src/TestWebsites/NET45/Test_Website_NET45/Web.config
index 110524d7e1..133506eeb3 100644
--- a/src/TestWebsites/NET45/Test_Website_NET45/Web.config
+++ b/src/TestWebsites/NET45/Test_Website_NET45/Web.config
@@ -16,7 +16,7 @@
-
+
diff --git a/src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config b/src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config
index 82ed2e9954..016f42636b 100644
--- a/src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config
+++ b/src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config
@@ -23,7 +23,7 @@
-
+