Browse Source

Added Watermark!

Added the ability to generate watermarks and performed a general tidy
up.


Former-commit-id: 5eefd1d7abc816eaacca7e02f551706adda10ecd
pull/17/head
JimBobSquarePants 14 years ago
parent
commit
3b91e81ede
  1. 6
      src/ImageProcessor.Web/ImageFactoryExtensions.cs
  2. 2
      src/ImageProcessor/Helpers/Extensions/EnumExtensions.cs
  3. 63
      src/ImageProcessor/ImageFactory.cs
  4. 3
      src/ImageProcessor/ImageProcessor.csproj
  5. 206
      src/ImageProcessor/ImageProcessor.vsdoc
  6. 138
      src/ImageProcessor/Imaging/PaletteQuantizer.cs
  7. 113
      src/ImageProcessor/Imaging/TextLayer.cs
  8. 4
      src/ImageProcessor/Processors/Alpha.cs
  9. 332
      src/ImageProcessor/Processors/Copy of Watermark.cs
  10. 4
      src/ImageProcessor/Processors/Crop.cs
  11. 37
      src/ImageProcessor/Processors/Filter.cs
  12. 4
      src/ImageProcessor/Processors/Resize.cs
  13. 4
      src/ImageProcessor/Processors/Vignette.cs
  14. 444
      src/ImageProcessor/Processors/Watermark.cs
  15. 2
      src/ImageProcessor/Properties/AssemblyInfo.cs

6
src/ImageProcessor.Web/ImageFactoryExtensions.cs

@ -34,8 +34,10 @@ namespace ImageProcessor.Web
{
// Get a list of all graphics processors that have parsed and matched the querystring.
List<IGraphicsProcessor> list =
ImageProcessorConfig.Instance.GraphicsProcessors.Where(x => x.MatchRegexIndex(factory.QueryString) != int.MaxValue).OrderBy(
y => y.SortOrder).ToList();
ImageProcessorConfig.Instance.GraphicsProcessors
.Where(x => x.MatchRegexIndex(factory.QueryString) != int.MaxValue)
.OrderBy(y => y.SortOrder)
.ToList();
// Loop through and process the image.
foreach (IGraphicsProcessor graphicsProcessor in list)

2
src/ImageProcessor/Helpers/Extensions/EnumExtensions.cs

@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
// <copyright file="EnumExtensions.cs" company="Peach James South">
// <copyright file="EnumExtensions.cs" company="James South">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

63
src/ImageProcessor/ImageFactory.cs

@ -20,7 +20,6 @@ namespace ImageProcessor
/// <summary>
/// Encapsulates methods for processing image files.
/// http://csharpindepth.com/Articles/General/Singleton.aspx
/// </summary>
public class ImageFactory : IDisposable
{
@ -177,7 +176,6 @@ namespace ImageProcessor
}
#region Manipulation
/// <summary>
/// Adds a querystring to the image factory to allow autoprocessing of remote files.
/// </summary>
@ -206,7 +204,7 @@ namespace ImageProcessor
{
if (this.ShouldProcess)
{
var alpha = new Alpha { DynamicParameter = percentage };
Alpha alpha = new Alpha { DynamicParameter = percentage };
this.Image = alpha.ProcessImage(this);
}
@ -227,7 +225,7 @@ namespace ImageProcessor
{
if (this.ShouldProcess)
{
var crop = new Crop { DynamicParameter = rectangle };
Crop crop = new Crop { DynamicParameter = rectangle };
this.Image = crop.ProcessImage(this);
}
@ -248,7 +246,7 @@ namespace ImageProcessor
{
if (this.ShouldProcess)
{
var filter = new Filter { DynamicParameter = filterName };
Filter filter = new Filter { DynamicParameter = filterName };
this.Image = filter.ProcessImage(this);
}
@ -304,7 +302,7 @@ namespace ImageProcessor
{
var resizeSettings = new Dictionary<string, string> { { "MaxWidth", width.ToString("G") }, { "MaxHeight", height.ToString("G") } };
var resize = new Resize { DynamicParameter = new Size(width, height), Settings = resizeSettings };
Resize resize = new Resize { DynamicParameter = new Size(width, height), Settings = resizeSettings };
this.Image = resize.ProcessImage(this);
}
@ -322,13 +320,34 @@ namespace ImageProcessor
{
if (this.ShouldProcess)
{
var vignette = new Vignette();
Vignette vignette = new Vignette();
this.Image = vignette.ProcessImage(this);
}
return this;
}
/// <summary>
/// Adds a text based watermark to the image
/// </summary>
/// <param name="textLayer">
/// The text layer containing the properties necessary to add the text based watermark to the image.
/// </param>
/// <returns>
/// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
/// </returns>
public ImageFactory Watermark(TextLayer textLayer)
{
if (this.ShouldProcess)
{
Watermark watermark = new Watermark { DynamicParameter = textLayer };
this.Image = watermark.ProcessImage(this);
}
return this;
}
#endregion
/// <summary>
@ -449,36 +468,6 @@ namespace ImageProcessor
}
#endregion
/// <summary>
/// Saves the current image to the specified file path and resets any internal parameters.
/// </summary>
/// <param name="filePath">The path to save the image to.</param>
private void SaveFile(string filePath)
{
// Fix the colour palette of gif images.
this.FixGifs();
if (this.ImageFormat == ImageFormat.Jpeg)
{
// Jpegs can be saved with different settings to include a quality setting for the JPEG compression.
// This improves output compression and quality.
using (EncoderParameters encoderParameters = ImageUtils.GetEncodingParameters(this.JpegQuality))
{
ImageCodecInfo imageCodecInfo = ImageCodecInfo.GetImageEncoders()
.FirstOrDefault(ici => ici.MimeType.Equals("image/jpeg", StringComparison.OrdinalIgnoreCase));
if (imageCodecInfo != null)
{
this.Image.Save(filePath, imageCodecInfo, encoderParameters);
}
}
}
else
{
this.Image.Save(filePath, this.ImageFormat);
}
}
/// <summary>
/// Uses the <see cref="T:ImageProcessor.Imaging.OctreeQuantizer"/>
/// to fix the colour palette of gif images.

3
src/ImageProcessor/ImageProcessor.csproj

@ -60,11 +60,11 @@
<Compile Include="Helpers\Extensions\EnumExtensions.cs" />
<Compile Include="Helpers\Extensions\StringExtensions.cs" />
<Compile Include="ImageFactory.cs" />
<Compile Include="Imaging\PaletteQuantizer.cs" />
<Compile Include="Imaging\ImageUtils.cs" />
<Compile Include="Imaging\OctreeQuantizer.cs" />
<Compile Include="Imaging\Quantizer.cs" />
<Compile Include="Imaging\ResponseType.cs" />
<Compile Include="Imaging\TextLayer.cs" />
<Compile Include="Processors\Alpha.cs" />
<Compile Include="Processors\Crop.cs" />
<Compile Include="Processors\Filter.cs" />
@ -73,6 +73,7 @@
<Compile Include="Processors\Resize.cs" />
<Compile Include="Processors\Format.cs" />
<Compile Include="Processors\Vignette.cs" />
<Compile Include="Processors\Watermark.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup />

206
src/ImageProcessor/ImageProcessor.vsdoc

@ -1,103 +1,105 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- VSdocman config file for current project/solution.-->
<activeProfile>default</activeProfile>
<appSettings>
<add key="VBdocman_regexFilters"><![CDATA[<?xml version="1.0" encoding="utf-8"?>
<filters />]]></add>
<add key="VBdocman_comNonCommented"><![CDATA[-1]]></add>
<add key="VBdocman_comPublic"><![CDATA[-1]]></add>
<add key="VBdocman_comPrivate"><![CDATA[0]]></add>
<add key="VBdocman_comFriend"><![CDATA[0]]></add>
<add key="VBdocman_comProtected"><![CDATA[0]]></add>
<add key="VBdocman_comProtectedFriend"><![CDATA[0]]></add>
<add key="VBdocman_comMethod"><![CDATA[-1]]></add>
<add key="VBdocman_comStdModule"><![CDATA[0]]></add>
<add key="VBdocman_comObject"><![CDATA[-1]]></add>
<add key="VBdocman_comForm"><![CDATA[-1]]></add>
<add key="VBdocman_comProperty"><![CDATA[-1]]></add>
<add key="VBdocman_comEvent"><![CDATA[-1]]></add>
<add key="VBdocman_comVariable"><![CDATA[0]]></add>
<add key="VBdocman_comConstant"><![CDATA[0]]></add>
<add key="VBdocman_comEnumeration"><![CDATA[0]]></add>
<add key="VBdocman_comStructure"><![CDATA[0]]></add>
<add key="VBdocman_comDelegate"><![CDATA[0]]></add>
<add key="VBdocman_comInterface"><![CDATA[0]]></add>
<add key="VBdocman_comAttribute"><![CDATA[0]]></add>
<add key="VBdocman_comEventDecl"><![CDATA[0]]></add>
<add key="VBdocman_comDeclare"><![CDATA[0]]></add>
<add key="VBdocman_comContextID"><![CDATA[0]]></add>
<add key="VBdocman_comWriteDescription"><![CDATA[-1]]></add>
<add key="VBdocman_useConditionalCompilation"><![CDATA[0]]></add>
<add key="VBdocman_conditionalConstants"><![CDATA[]]></add>
<add key="VBdocman_showFormsSeparate"><![CDATA[0]]></add>
<add key="VBdocman_showInherited"><![CDATA[-1]]></add>
<add key="VBdocman_indentMode"><![CDATA[0]]></add>
<add key="VBdocman_insertSourceGlobal"><![CDATA[0]]></add>
<add key="VBdocman_unbreakSourceLines"><![CDATA[0]]></add>
<add key="VBdocman_removeAttributes"><![CDATA[0]]></add>
<add key="VBdocman_generateVbSyntax"><![CDATA[-1]]></add>
<add key="VBdocman_generateCsharpSyntax"><![CDATA[-1]]></add>
<add key="VBdocman_generateCppSyntax"><![CDATA[-1]]></add>
<add key="VBdocman_generateJscriptSyntax"><![CDATA[-1]]></add>
<add key="VBdocman_supportedPlatforms"><![CDATA[Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition]]></add>
<add key="VBdocman_supportedNetFramework"><![CDATA[3.0, 2.0, 1.1, 1.0]]></add>
<add key="VBdocman_supportedNetCompactFramework"><![CDATA[2.0, 1.0]]></add>
<add key="VBdocman_supportedXnaFramework"><![CDATA[1.0]]></add>
<add key="VBdocman_customVar1"><![CDATA[]]></add>
<add key="VBdocman_customVar2"><![CDATA[]]></add>
<add key="VBdocman_customVar3"><![CDATA[]]></add>
<add key="VBdocman_titlePageText"><![CDATA[]]></add>
<add key="VBdocman_rootNamespaceText"><![CDATA[]]></add>
<add key="VBdocman_rootNamespaceCommentStyle"><![CDATA[2]]></add>
<add key="VBdocman_pageFooterText"><![CDATA[Generated by VSdocman]]></add>
<add key="VBdocman_outputPath"><![CDATA[$(ProjectDir)VSdoc]]></add>
<add key="VBdocman_templateFolder"><![CDATA[$(VSdocmanDir)Templates]]></add>
<add key="VBdocman_externalFilesFolder"><![CDATA[]]></add>
<add key="VBdocman_fileNamingConvention"><![CDATA[1]]></add>
<add key="VBdocman_templateLocale"><![CDATA[en-US]]></add>
<add key="VBdocman_templatePath"><![CDATA[chm_msdn2.vbdt]]></add>
<add key="VBdocman_enumSorting"><![CDATA[1]]></add>
<add key="VBdocman_helpTitle"><![CDATA[ImageProcessor Reference]]></add>
<add key="VBdocman_customTopics"><![CDATA[<?xml version="1.0" encoding="utf-8"?>
<topics>
<topic>
<type>normal</type>
<is-default>yes</is-default>
<name>ImageProcessor Reference</name>
<id>imageprocessor_reference</id>
<comment><![CDATA[<summary></summary>vsdocman_escaped_]_]_></comment>
<namespaces />
<topics>
<topic>
<type>placeholder</type>
<is-default>no</is-default>
<name />
<id>e3cba20ec62e422b8bb39e6be7ca2142</id>
<comment><![CDATA[vsdocman_escaped_]_]_></comment>
<namespaces />
<topics />
</topic>
</topics>
</topic>
</topics>]]></add>
<add key="VBdocman_linkForExternalNotInFramework"><![CDATA[0]]></add>
<add key="VBdocman_allowMacrosInComments"><![CDATA[0]]></add>
<add key="VBdocman_emptyOutputFolder"><![CDATA[0]]></add>
<add key="VBdocman_comModules_Helpers...Extensions...EnumExtensions.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Helpers...Extensions...StringExtensions.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_ImageFactory.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Imaging...ImageUtils.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Imaging...OctreeQuantizer.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Imaging...Quantizer.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Imaging...ResponseType.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Processors...Alpha.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Processors...Class1.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Processors...Crop.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Processors...Filter.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Processors...Quality.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Processors...Resize.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Processors...Vignette.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Properties...AssemblyInfo.cs"><![CDATA[On]]></add>
</appSettings>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- VSdocman config file for current project/solution.-->
<activeProfile>default</activeProfile>
<appSettings>
<add key="VBdocman_regexFilters"><![CDATA[<?xml version="1.0" encoding="utf-8"?>
<filters />]]></add>
<add key="VBdocman_comNonCommented"><![CDATA[-1]]></add>
<add key="VBdocman_comPublic"><![CDATA[-1]]></add>
<add key="VBdocman_comPrivate"><![CDATA[0]]></add>
<add key="VBdocman_comFriend"><![CDATA[0]]></add>
<add key="VBdocman_comProtected"><![CDATA[0]]></add>
<add key="VBdocman_comProtectedFriend"><![CDATA[0]]></add>
<add key="VBdocman_comMethod"><![CDATA[-1]]></add>
<add key="VBdocman_comStdModule"><![CDATA[0]]></add>
<add key="VBdocman_comObject"><![CDATA[-1]]></add>
<add key="VBdocman_comForm"><![CDATA[-1]]></add>
<add key="VBdocman_comProperty"><![CDATA[-1]]></add>
<add key="VBdocman_comEvent"><![CDATA[-1]]></add>
<add key="VBdocman_comVariable"><![CDATA[0]]></add>
<add key="VBdocman_comConstant"><![CDATA[0]]></add>
<add key="VBdocman_comEnumeration"><![CDATA[0]]></add>
<add key="VBdocman_comStructure"><![CDATA[0]]></add>
<add key="VBdocman_comDelegate"><![CDATA[0]]></add>
<add key="VBdocman_comInterface"><![CDATA[0]]></add>
<add key="VBdocman_comAttribute"><![CDATA[0]]></add>
<add key="VBdocman_comEventDecl"><![CDATA[0]]></add>
<add key="VBdocman_comDeclare"><![CDATA[0]]></add>
<add key="VBdocman_comContextID"><![CDATA[0]]></add>
<add key="VBdocman_comWriteDescription"><![CDATA[-1]]></add>
<add key="VBdocman_useConditionalCompilation"><![CDATA[0]]></add>
<add key="VBdocman_conditionalConstants"><![CDATA[]]></add>
<add key="VBdocman_showFormsSeparate"><![CDATA[0]]></add>
<add key="VBdocman_showInherited"><![CDATA[-1]]></add>
<add key="VBdocman_indentMode"><![CDATA[0]]></add>
<add key="VBdocman_insertSourceGlobal"><![CDATA[0]]></add>
<add key="VBdocman_unbreakSourceLines"><![CDATA[0]]></add>
<add key="VBdocman_removeAttributes"><![CDATA[0]]></add>
<add key="VBdocman_generateVbSyntax"><![CDATA[-1]]></add>
<add key="VBdocman_generateCsharpSyntax"><![CDATA[-1]]></add>
<add key="VBdocman_generateCppSyntax"><![CDATA[-1]]></add>
<add key="VBdocman_generateJscriptSyntax"><![CDATA[-1]]></add>
<add key="VBdocman_supportedPlatforms"><![CDATA[Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition]]></add>
<add key="VBdocman_supportedNetFramework"><![CDATA[3.0, 2.0, 1.1, 1.0]]></add>
<add key="VBdocman_supportedNetCompactFramework"><![CDATA[2.0, 1.0]]></add>
<add key="VBdocman_supportedXnaFramework"><![CDATA[1.0]]></add>
<add key="VBdocman_customVar1"><![CDATA[]]></add>
<add key="VBdocman_customVar2"><![CDATA[]]></add>
<add key="VBdocman_customVar3"><![CDATA[]]></add>
<add key="VBdocman_titlePageText"><![CDATA[]]></add>
<add key="VBdocman_rootNamespaceText"><![CDATA[]]></add>
<add key="VBdocman_rootNamespaceCommentStyle"><![CDATA[2]]></add>
<add key="VBdocman_pageFooterText"><![CDATA[Generated by VSdocman]]></add>
<add key="VBdocman_outputPath"><![CDATA[$(ProjectDir)VSdoc]]></add>
<add key="VBdocman_templateFolder"><![CDATA[$(VSdocmanDir)Templates]]></add>
<add key="VBdocman_externalFilesFolder"><![CDATA[]]></add>
<add key="VBdocman_fileNamingConvention"><![CDATA[1]]></add>
<add key="VBdocman_templateLocale"><![CDATA[en-US]]></add>
<add key="VBdocman_templatePath"><![CDATA[chm_msdn2.vbdt]]></add>
<add key="VBdocman_enumSorting"><![CDATA[1]]></add>
<add key="VBdocman_helpTitle"><![CDATA[ImageProcessor Reference]]></add>
<add key="VBdocman_customTopics"><![CDATA[<?xml version="1.0" encoding="utf-8"?>
<topics>
<topic>
<type>normal</type>
<is-default>yes</is-default>
<name>ImageProcessor Reference</name>
<id>imageprocessor_reference</id>
<comment><![CDATA[<summary></summary>vsdocman_escaped_]_]_></comment>
<namespaces />
<topics>
<topic>
<type>placeholder</type>
<is-default>no</is-default>
<name />
<id>e3cba20ec62e422b8bb39e6be7ca2142</id>
<comment><![CDATA[vsdocman_escaped_]_]_></comment>
<namespaces />
<topics />
</topic>
</topics>
</topic>
</topics>]]></add>
<add key="VBdocman_linkForExternalNotInFramework"><![CDATA[0]]></add>
<add key="VBdocman_allowMacrosInComments"><![CDATA[0]]></add>
<add key="VBdocman_emptyOutputFolder"><![CDATA[0]]></add>
<add key="VBdocman_comModules_Helpers...Extensions...EnumExtensions.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Helpers...Extensions...StringExtensions.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_ImageFactory.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Imaging...ImageUtils.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Imaging...OctreeQuantizer.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Imaging...Quantizer.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Imaging...ResponseType.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Imaging...TextLayer.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Processors...Alpha.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Processors...Copy of Watermark.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Processors...Crop.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Processors...Filter.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Processors...Quality.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Processors...Resize.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Processors...Vignette.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Processors...Watermark.cs"><![CDATA[On]]></add>
<add key="VBdocman_comModules_Properties...AssemblyInfo.cs"><![CDATA[On]]></add>
</appSettings>
</configuration>

138
src/ImageProcessor/Imaging/PaletteQuantizer.cs

@ -1,138 +0,0 @@
// -----------------------------------------------------------------------
// <copyright file="PaletteQuantizer.cs" company="James South">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------
namespace ImageProcessor.Imaging
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
/// <summary>
/// Encapsulates methods to calculate the colour palette if an image.
/// http://codebetter.com/brendantompkins/2007/06/14/gif-image-color-quantizer-now-with-safe-goodness/
/// </summary>
internal class PaletteQuantizer : Quantizer
{
/// <summary>
/// Initializes a new instance of the <see cref="PaletteQuantizer"/> class.
/// </summary>
/// <param name="palette">
/// The color palette to quantize to
/// </param>
/// <remarks>
/// Palette quantization only requires a single quantization step
/// </remarks>
public PaletteQuantizer(ArrayList palette)
: base(true)
{
_colorMap = new Hashtable();
_colors = new Color[palette.Count];
palette.CopyTo(_colors);
}
/// <summary>
/// Override this to process the pixel in the second pass of the algorithm
/// </summary>
/// <param name="pixel">The pixel to quantize</param>
/// <returns>The quantized value</returns>
protected override byte QuantizePixel(Color32 pixel)
{
byte colorIndex = 0;
int colorHash = pixel.ARGB;
// Check if the color is in the lookup table
if (_colorMap.ContainsKey(colorHash))
{
colorIndex = (byte)_colorMap[colorHash];
}
else
{
// Not found - loop through the palette and find the nearest match.
// Firstly check the alpha value - if 0, lookup the transparent color
if (0 == pixel.Alpha)
{
// Transparent. Lookup the first color with an alpha value of 0
for (int index = 0; index < _colors.Length; index++)
{
if (0 == _colors[index].A)
{
colorIndex = (byte)index;
break;
}
}
}
else
{
// Not transparent...
int leastDistance = int.MaxValue;
int red = pixel.Red;
int green = pixel.Green;
int blue = pixel.Blue;
// Loop through the entire palette, looking for the closest color match
for (int index = 0; index < _colors.Length; index++)
{
Color paletteColor = _colors[index];
int redDistance = paletteColor.R - red;
int greenDistance = paletteColor.G - green;
int blueDistance = paletteColor.B - blue;
int distance = (redDistance * redDistance) +
(greenDistance * greenDistance) +
(blueDistance * blueDistance);
if (distance < leastDistance)
{
colorIndex = (byte)index;
leastDistance = distance;
// And if it's an exact match, exit the loop
if (0 == distance)
{
break;
}
}
}
}
// Now I have the color, pop it into the hashtable for next time
_colorMap.Add(colorHash, colorIndex);
}
return colorIndex;
}
/// <summary>
/// Retrieve the palette for the quantized image
/// </summary>
/// <param name="palette">Any old palette, this is overrwritten</param>
/// <returns>The new color palette</returns>
protected override ColorPalette GetPalette(ColorPalette palette)
{
for (int index = 0; index < _colors.Length; index++)
{
palette.Entries[index] = _colors[index];
}
return palette;
}
/// <summary>
/// Lookup table for colors
/// </summary>
private Hashtable _colorMap;
/// <summary>
/// List of all colors in the palette
/// </summary>
protected Color[] _colors;
}
}

113
src/ImageProcessor/Imaging/TextLayer.cs

@ -0,0 +1,113 @@
// -----------------------------------------------------------------------
// <copyright file="TextLayer.cs" company="James South">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------
namespace ImageProcessor.Imaging
{
#region Using
using System;
using System.Drawing;
#endregion
/// <summary>
/// Enacapsulates the properties required to add a leyer of text to an image.
/// </summary>
public class TextLayer
{
#region Fields
/// <summary>
/// The colour to render the text.
/// </summary>
private Color textColor = Color.Black;
/// <summary>
/// The opacity at which to render the text.
/// </summary>
private int opacity = 100;
/// <summary>
/// The font style to render the text.
/// </summary>
private FontStyle fontStyle = FontStyle.Bold;
/// <summary>
/// The font size to render the text.
/// </summary>
private int fontSize = 48;
/// <summary>
/// The position to start creating the text from.
/// </summary>
private Point position = Point.Empty;
#endregion
#region Properties
/// <summary>
/// Gets or sets Text.
/// </summary>
public string Text { get; set; }
/// <summary>
/// Gets or sets TextColor.
/// </summary>
public Color TextColor
{
get { return this.textColor; }
set { this.textColor = value; }
}
/// <summary>
/// Gets or sets the name of the font.
/// </summary>
public string Font { get; set; }
/// <summary>
/// Gets or sets the size of the font in pixels.
/// </summary>
public int FontSize
{
get { return this.fontSize; }
set { this.fontSize = value; }
}
/// <summary>
/// Gets or sets the FontStyle.
/// </summary>
public FontStyle Style
{
get { return this.fontStyle; }
set { this.fontStyle = value; }
}
/// <summary>
/// Gets or sets the Opacity.
/// </summary>
public int Opacity
{
get
{
int alpha = (int)Math.Ceiling((this.opacity / 100d) * 255);
return alpha < 255 ? alpha : 255;
}
set
{
this.opacity = value;
}
}
/// <summary>
/// Gets or sets Position.
/// </summary>
public Point Position
{
get { return this.position; }
set { this.position = value; }
}
#endregion
}
}

4
src/ImageProcessor/Processors/Alpha.cs

@ -141,7 +141,9 @@ namespace ImageProcessor.Processors
{
int alphaPercent = this.DynamicParameter;
newImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppPArgb) { Tag = image.Tag };
// Dont use an object initializer here.
newImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppPArgb);
newImage.Tag = image.Tag;
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.Matrix00 = colorMatrix.Matrix11 = colorMatrix.Matrix22 = colorMatrix.Matrix44 = 1;

332
src/ImageProcessor/Processors/Copy of Watermark.cs

@ -0,0 +1,332 @@
// -----------------------------------------------------------------------
// <copyright file="Watermark.cs" company="James South">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------
namespace ImageProcessor.Processors
{
#region Using
using System.Collections.Generic;
using System.Drawing;
using System.Text.RegularExpressions;
using ImageProcessor.Helpers.Extensions;
using ImageProcessor.Imaging;
#endregion
/// <summary>
/// Encapsulates methods to change the alpha component of the image to effect its transparency.
/// </summary>
public class Watermark : IGraphicsProcessor
{
/// <summary>
/// The regular expression to search strings for.
/// http://stackoverflow.com/questions/11263949/optimize-a-variable-regex
/// </summary>
private static readonly Regex QueryRegex = new Regex(@"watermark=(text-\w+\|position-\d+-\d+(\|color-([0-9a-fA-F]{3}){1,2}(\|size-\d+(\|style-(bold|italic|regular|strikeout|underline))?)?)?|\w+)", RegexOptions.Compiled);
#region IGraphicsProcessor Members
/// <summary>
/// Gets the name.
/// </summary>
public string Name
{
get
{
return "Watermark";
}
}
/// <summary>
/// Gets the description.
/// </summary>
public string Description
{
get
{
return "Adds a watermark containing text to the image.";
}
}
/// <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;
TextLayer textLayer = new TextLayer();
// Split the string up.
string[] firstPass = match.Value.Split('=')[1].Split('|');
switch (firstPass.Length)
{
case 1:
textLayer.Text = firstPass[0];
break;
case 2:
textLayer.Text = firstPass[0];
textLayer.Position = this.GetPosition(firstPass[1]);
break;
case 3:
textLayer.Text = firstPass[0];
textLayer.Position = this.GetPosition(firstPass[1]);
textLayer.TextColor = this.GetColor(firstPass[2]);
break;
case 4:
textLayer.Text = firstPass[0];
textLayer.Position = this.GetPosition(firstPass[1]);
textLayer.TextColor = this.GetColor(firstPass[2]);
textLayer.FontSize = this.GetFontSize(firstPass[3]);
break;
case 5:
textLayer.Text = firstPass[0];
textLayer.Position = this.GetPosition(firstPass[1]);
textLayer.TextColor = this.GetColor(firstPass[2]);
textLayer.FontSize = this.GetFontSize(firstPass[3]);
textLayer.Style = this.GetFontStyle(firstPass[4]);
break;
}
this.DynamicParameter = textLayer;
}
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
{
newImage = new Bitmap(image) { Tag = image.Tag };
TextLayer textLayer = this.DynamicParameter;
string text = textLayer.Text;
int opacity = textLayer.Opacity;
int fontSize = textLayer.FontSize;
FontStyle fontStyle = textLayer.Style;
using (Graphics graphics = Graphics.FromImage(newImage))
{
using (Font font = this.GetFont(textLayer.Font, fontSize, fontStyle))
{
using (StringFormat drawFormat = new StringFormat())
{
using (Brush brush = new SolidBrush(Color.FromArgb(opacity, textLayer.TextColor)))
{
Point origin = textLayer.Position;
// We need to ensure that there is a position set for the watermark
if (origin == Point.Empty)
{
// Work out the size of the text.
SizeF textSize = graphics.MeasureString(text, font, new SizeF(image.Width, image.Height), drawFormat);
int x = (int)(image.Width - textSize.Width) / 2;
int y = (int)(image.Height - textSize.Height) / 2;
origin = new Point(x, y);
}
graphics.DrawString(text, font, brush, origin, drawFormat);
}
}
}
image.Dispose();
image = newImage;
}
}
catch
{
if (newImage != null)
{
newImage.Dispose();
}
}
return image;
}
#endregion
#region Private Methods
/// <summary>
/// Returns the correct <see cref="T:System.Drawing.Font"/> for the given parameters
/// </summary>
/// <param name="font">
/// The font.
/// </param>
/// <param name="fontSize">
/// The font size.
/// </param>
/// <param name="fontStyle">
/// The font style.
/// </param>
/// <returns>
/// The correct <see cref="T:System.Drawing.Font"/>
/// </returns>
private Font GetFont(string font, int fontSize, FontStyle fontStyle)
{
FontFamily fontFamily = string.IsNullOrEmpty(font) ? FontFamily.GenericSansSerif : new FontFamily(font);
return new Font(fontFamily, fontSize, fontStyle, GraphicsUnit.Pixel);
}
/// <summary>
/// Returns the correct <see cref="T:System.Drawing.Point"/> for the given string.
/// </summary>
/// <param name="input">
/// The input string containing the value to parse.
/// </param>
/// <returns>
/// The correct <see cref="T:System.Drawing.Point"/>
/// </returns>
private Point GetPosition(string input)
{
int[] position = input.ToIntegerArray();
int x = position[0];
int y = position[1];
return new Point(x, y);
}
/// <summary>
/// Returns the correct <see cref="T:System.Drawing.Color"/> for the given string.
/// </summary>
/// <param name="input">
/// The input string containing the value to parse.
/// </param>
/// <returns>
/// The correct <see cref="T:System.Drawing.Color"/>
/// </returns>
private Color GetColor(string input)
{
// split on color-hex
return ColorTranslator.FromHtml("#" + input.Split('-')[1]);
}
/// <summary>
/// Returns the correct <see cref="T:System.Int32"/> for the given string.
/// </summary>
/// <param name="input">
/// The input string containing the value to parse.
/// </param>
/// <returns>
/// The correct <see cref="T:System.Int32"/>
/// </returns>
private int GetFontSize(string input)
{
// split on size-value
return int.Parse(input.Split('-')[1]);
}
/// <summary>
/// Returns the correct <see cref="T:System.Drawing.FontStyle"/> for the given string.
/// </summary>
/// <param name="input">
/// The string containing the respective fontstyle.
/// </param>
/// <returns>
/// The correct <see cref="T:System.Drawing.FontStyle"/>
/// </returns>
private FontStyle GetFontStyle(string input)
{
FontStyle fontStyle = FontStyle.Bold;
switch (input.ToLowerInvariant())
{
case "italic":
fontStyle = FontStyle.Italic;
break;
case "regular":
fontStyle = FontStyle.Regular;
break;
case "strikeout":
fontStyle = FontStyle.Strikeout;
break;
case "underline":
fontStyle = FontStyle.Underline;
break;
}
return fontStyle;
}
#endregion
}
}

4
src/ImageProcessor/Processors/Crop.cs

@ -162,7 +162,9 @@ namespace ImageProcessor.Processors
rectangle.Height = sourceHeight - rectangle.Y;
}
newImage = new Bitmap(rectangle.Width, rectangle.Height, PixelFormat.Format32bppPArgb) { Tag = image.Tag };
// Dont use an object initializer here.
newImage = new Bitmap(rectangle.Width, rectangle.Height, PixelFormat.Format32bppPArgb);
newImage.Tag = image.Tag;
using (Graphics graphics = Graphics.FromImage(newImage))
{

37
src/ImageProcessor/Processors/Filter.cs

@ -35,9 +35,24 @@ namespace ImageProcessor.Processors
/// </summary>
private enum ChannelArgb
{
/// <summary>
/// The blue channel
/// </summary>
Blue = 0,
/// <summary>
/// The green channel
/// </summary>
Green = 1,
/// <summary>
/// The red channel
/// </summary>
Red = 2,
/// <summary>
/// The alpha channel
/// </summary>
Alpha = 3
}
@ -150,9 +165,15 @@ namespace ImageProcessor.Processors
{
Bitmap newImage = null;
Image image = factory.Image;
// Bitmaps for comic pattern
Bitmap hisatchBitmap = null;
Bitmap patternBitmap = null;
try
{
newImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppPArgb) { Tag = image.Tag };
// Dont use an object initializer here.
newImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppPArgb);
newImage.Tag = image.Tag;
ColorMatrix colorMatrix = null;
@ -207,7 +228,7 @@ namespace ImageProcessor.Processors
graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
// Create a bitmap for overlaying.
Bitmap hisatchBitmap = new Bitmap(rectangle.Width, rectangle.Height, PixelFormat.Format32bppPArgb);
hisatchBitmap = new Bitmap(rectangle.Width, rectangle.Height, PixelFormat.Format32bppPArgb);
// Set the color matrix
attributes.SetColorMatrix(ColorMatrixes.HiSatch);
@ -220,7 +241,7 @@ namespace ImageProcessor.Processors
// We need to create a new image now with the hi saturation colormatrix and a pattern mask to paint it
// onto the other image with.
Bitmap patternBitmap = new Bitmap(rectangle.Width, rectangle.Height, PixelFormat.Format32bppPArgb);
patternBitmap = new Bitmap(rectangle.Width, rectangle.Height, PixelFormat.Format32bppPArgb);
// Create the pattern mask.
using (var g = Graphics.FromImage(patternBitmap))
@ -318,6 +339,16 @@ namespace ImageProcessor.Processors
{
newImage.Dispose();
}
if (hisatchBitmap != null)
{
hisatchBitmap.Dispose();
}
if (patternBitmap != null)
{
patternBitmap.Dispose();
}
}
return image;

4
src/ImageProcessor/Processors/Resize.cs

@ -176,7 +176,9 @@ namespace ImageProcessor.Processors
if (width > 0 && height > 0 && width <= maxWidth && height <= maxHeight)
{
newImage = new Bitmap(width, height, PixelFormat.Format32bppPArgb) { Tag = image.Tag };
// Dont use an object initializer here.
newImage = new Bitmap(width, height, PixelFormat.Format32bppPArgb);
newImage.Tag = image.Tag;
using (Graphics graphics = Graphics.FromImage(newImage))
{

4
src/ImageProcessor/Processors/Vignette.cs

@ -137,7 +137,9 @@ namespace ImageProcessor.Processors
try
{
newImage = new Bitmap(image) { Tag = image.Tag };
// Dont use an object initializer here.
newImage = new Bitmap(image);
newImage.Tag = image.Tag;
using (Graphics graphics = Graphics.FromImage(newImage))
{

444
src/ImageProcessor/Processors/Watermark.cs

@ -0,0 +1,444 @@
// -----------------------------------------------------------------------
// <copyright file="Watermark.cs" company="James South">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------
namespace ImageProcessor.Processors
{
#region Using
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Text;
using System.Text.RegularExpressions;
using ImageProcessor.Helpers.Extensions;
using ImageProcessor.Imaging;
#endregion
/// <summary>
/// Encapsulates methods to change the alpha component of the image to effect its transparency.
/// </summary>
public class Watermark : IGraphicsProcessor
{
/// <summary>
/// The regular expression to search strings for.
/// </summary>
private static readonly Regex QueryRegex = new Regex(@"watermark=[^&]*", RegexOptions.Compiled);
/// <summary>
/// The regular expression to search strings for the text attribute.
/// </summary>
private static readonly Regex TextRegex = new Regex(@"text-[^/:?#\[\]@!$&'()*%\|,;=]+", RegexOptions.Compiled);
/// <summary>
/// The regular expression to search strings for the position attribute.
/// </summary>
private static readonly Regex PositionRegex = new Regex(@"position-\d+-\d+", RegexOptions.Compiled);
/// <summary>
/// The regular expression to search strings for the color attribute.
/// </summary>
private static readonly Regex ColorRegex = new Regex(@"color-([0-9a-fA-F]{3}){1,2}", RegexOptions.Compiled);
/// <summary>
/// The regular expression to search strings for the fontsize attribute.
/// </summary>
private static readonly Regex FontSizeRegex = new Regex(@"size-\d{1,3}", RegexOptions.Compiled);
/// <summary>
/// The regular expression to search strings for the fontstyle attribute.
/// </summary>
private static readonly Regex FontStyleRegex = new Regex(@"style-(bold|italic|regular|strikeout|underline)", RegexOptions.Compiled);
/// <summary>
/// The regular expression to search strings for the font family attribute.
/// </summary>
private static readonly Regex FontFamilyRegex = new Regex(@"font-[^/:?#\[\]@!$&'()*%\|,;=0-9]+", RegexOptions.Compiled);
/// <summary>
/// The regular expression to search strings for the opacity attribute.
/// </summary>
private static readonly Regex OpacityRegex = new Regex(@"opacity-\d{1,2}(?!\d)|opacity-100", RegexOptions.Compiled);
#region IGraphicsProcessor Members
/// <summary>
/// Gets the name.
/// </summary>
public string Name
{
get
{
return "Watermark";
}
}
/// <summary>
/// Gets the description.
/// </summary>
public string Description
{
get
{
return "Adds a watermark containing text to the image.";
}
}
/// <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;
TextLayer textLayer = new TextLayer();
string toParse = match.Value;
textLayer.Text = this.ParseText(toParse);
textLayer.Position = this.ParsePosition(toParse);
textLayer.TextColor = this.ParseColor(toParse);
textLayer.FontSize = this.ParseFontSize(toParse);
textLayer.Font = this.ParseFontFamily(toParse);
textLayer.Style = this.ParseFontStyle(toParse);
textLayer.Opacity = this.ParseOpacity(toParse);
this.DynamicParameter = textLayer;
}
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
{
// Dont use an object initializer here.
newImage = new Bitmap(image);
newImage.Tag = image.Tag;
TextLayer textLayer = this.DynamicParameter;
string text = textLayer.Text;
int opacity = textLayer.Opacity;
int fontSize = textLayer.FontSize;
FontStyle fontStyle = textLayer.Style;
using (Graphics graphics = Graphics.FromImage(newImage))
{
using (Font font = this.GetFont(textLayer.Font, fontSize, fontStyle))
{
using (StringFormat drawFormat = new StringFormat())
{
using (Brush brush = new SolidBrush(Color.FromArgb(opacity, textLayer.TextColor)))
{
Point origin = textLayer.Position;
// We need to ensure that there is a position set for the watermark
if (origin == Point.Empty)
{
// Work out the size of the text.
SizeF textSize = graphics.MeasureString(text, font, new SizeF(image.Width, image.Height), drawFormat);
int x = (int)(image.Width - textSize.Width) / 2;
int y = (int)(image.Height - textSize.Height) / 2;
origin = new Point(x, y);
}
// Set the hinting and draw the text.
graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
graphics.DrawString(text, font, brush, origin, drawFormat);
}
}
}
image.Dispose();
image = newImage;
}
}
catch
{
if (newImage != null)
{
newImage.Dispose();
}
}
return image;
}
#endregion
#region Private Methods
/// <summary>
/// Returns the correct <see cref="T:System.Drawing.Font"/> for the given parameters
/// </summary>
/// <param name="font">
/// The font.
/// </param>
/// <param name="fontSize">
/// The font size.
/// </param>
/// <param name="fontStyle">
/// The font style.
/// </param>
/// <returns>
/// The correct <see cref="T:System.Drawing.Font"/>
/// </returns>
private Font GetFont(string font, int fontSize, FontStyle fontStyle)
{
try
{
using (FontFamily fontFamily = new FontFamily(font))
{
return new Font(fontFamily, fontSize, fontStyle, GraphicsUnit.Pixel);
}
}
catch
{
using (FontFamily fontFamily = FontFamily.GenericSansSerif)
{
return new Font(fontFamily, fontSize, fontStyle, GraphicsUnit.Pixel);
}
}
}
/// <summary>
/// Returns the correct <see cref="T:System.String"/> for the given string.
/// </summary>
/// <param name="input">
/// The input string containing the value to parse.
/// </param>
/// <returns>
/// The correct <see cref="T:System.String"/> for the given string.
/// </returns>
private string ParseText(string input)
{
foreach (Match match in TextRegex.Matches(input))
{
// split on text-
return match.Value.Split('-')[1].Replace("+", " ");
}
return string.Empty;
}
/// <summary>
/// Returns the correct <see cref="T:System.Drawing.Point"/> for the given string.
/// </summary>
/// <param name="input">
/// The input string containing the value to parse.
/// </param>
/// <returns>
/// The correct <see cref="T:System.Drawing.Point"/>
/// </returns>
private Point ParsePosition(string input)
{
foreach (Match match in PositionRegex.Matches(input))
{
int[] position = match.Value.ToIntegerArray();
if (position != null)
{
int x = position[0];
int y = position[1];
return new Point(x, y);
}
}
return Point.Empty;
}
/// <summary>
/// Returns the correct <see cref="T:System.Drawing.Color"/> for the given string.
/// </summary>
/// <param name="input">
/// The input string containing the value to parse.
/// </param>
/// <returns>
/// The correct <see cref="T:System.Drawing.Color"/>
/// </returns>
private Color ParseColor(string input)
{
foreach (Match match in ColorRegex.Matches(input))
{
// split on color-hex
return ColorTranslator.FromHtml("#" + match.Value.Split('-')[1]);
}
return Color.Black;
}
/// <summary>
/// Returns the correct <see cref="T:System.Int32"/> for the given string.
/// </summary>
/// <param name="input">
/// The input string containing the value to parse.
/// </param>
/// <returns>
/// The correct <see cref="T:System.Int32"/>
/// </returns>
private int ParseFontSize(string input)
{
foreach (Match match in FontSizeRegex.Matches(input))
{
// split on size-value
return int.Parse(match.Value.Split('-')[1]);
}
// Matches the default number in TextLayer.
return 48;
}
/// <summary>
/// Returns the correct <see cref="T:System.Drawing.FontStyle"/> for the given string.
/// </summary>
/// <param name="input">
/// The string containing the respective fontstyle.
/// </param>
/// <returns>
/// The correct <see cref="T:System.Drawing.FontStyle"/>
/// </returns>
private FontStyle ParseFontStyle(string input)
{
FontStyle fontStyle = FontStyle.Bold;
foreach (Match match in FontStyleRegex.Matches(input))
{
// split on style-
switch (match.Value.Split('-')[1])
{
case "italic":
fontStyle = FontStyle.Italic;
break;
case "regular":
fontStyle = FontStyle.Regular;
break;
case "strikeout":
fontStyle = FontStyle.Strikeout;
break;
case "underline":
fontStyle = FontStyle.Underline;
break;
}
}
return fontStyle;
}
/// <summary>
/// Returns the correct <see cref="T:System.String"/> containing the font family for the given string.
/// </summary>
/// <param name="input">
/// The input string containing the value to parse.
/// </param>
/// <returns>
/// The correct <see cref="T:System.String"/> containing the font family for the given string.
/// </returns>
private string ParseFontFamily(string input)
{
foreach (Match match in FontFamilyRegex.Matches(input))
{
// split on font-
string font = match.Value.Split('-')[1].Replace("+", " ");
return font;
}
return string.Empty;
}
/// <summary>
/// Returns the correct <see cref="T:System.Int32"/> containing the opacity for the given string.
/// </summary>
/// <param name="input">
/// The input string containing the value to parse.
/// </param>
/// <returns>
/// The correct <see cref="T:System.Int32"/> containing the font family for the given string.
/// </returns>
private int ParseOpacity(string input)
{
foreach (Match match in OpacityRegex.Matches(input))
{
// split on opacity-
return int.Parse(match.Value.Split('-')[1]);
}
// full opacity - matches the Textlayer default.
return 100;
}
#endregion
}
}

2
src/ImageProcessor/Properties/AssemblyInfo.cs

@ -1,6 +1,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
@ -34,3 +35,4 @@ using System.Runtime.InteropServices;
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Loading…
Cancel
Save