Browse Source

v1.7.0.2

Watermark now automatically wraps text.


Former-commit-id: 38e144ab55565757aae5d8a391e39ecb96fd194f
af/merge-core
James South 13 years ago
parent
commit
9b4e401ab5
  1. 110
      src/ImageProcessor/Processors/Watermark.cs
  2. 4
      src/ImageProcessor/Properties/AssemblyInfo.cs
  3. BIN
      src/Nuget/ImageProcessor.1.7.0.2.nupkg
  4. 4
      src/Nuget/imageprocessor.128.png
  5. 2
      src/TestWebsites/NET45/Test_Website_NET45/Views/Home/Index.cshtml

110
src/ImageProcessor/Processors/Watermark.cs

@ -24,50 +24,50 @@ namespace ImageProcessor.Processors
/// </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 font size attribute.
/// </summary>
private static readonly Regex FontSizeRegex = new Regex(@"size-\d{1,3}", RegexOptions.Compiled);
/// <summary>
/// The regular expression to search strings for the font style 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-(?:100|[1-9]?[0-9])", RegexOptions.Compiled);
/// <summary>
/// The regular expression to search strings for the shadow attribute.
/// </summary>
private static readonly Regex ShadowRegex = new Regex(@"shadow-true", RegexOptions.Compiled);
/// <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 font size attribute.
/// </summary>
private static readonly Regex FontSizeRegex = new Regex(@"size-\d{1,3}", RegexOptions.Compiled);
/// <summary>
/// The regular expression to search strings for the font style 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-(?:100|[1-9]?[0-9])", RegexOptions.Compiled);
/// <summary>
/// The regular expression to search strings for the shadow attribute.
/// </summary>
private static readonly Regex ShadowRegex = new Regex(@"shadow-true", RegexOptions.Compiled);
#region IGraphicsProcessor Members
/// <summary>
@ -173,7 +173,7 @@ private static readonly Regex ShadowRegex = new Regex(@"shadow-true", RegexOptio
try
{
// Dont use an object initializer here.
// Don't use an object initializer here.
newImage = new Bitmap(image);
newImage.Tag = image.Tag;
@ -193,12 +193,12 @@ private static readonly Regex ShadowRegex = new Regex(@"shadow-true", RegexOptio
{
Point origin = textLayer.Position;
// Work out the size of the text.
SizeF textSize = graphics.MeasureString(text, font, new SizeF(image.Width, image.Height), drawFormat);
// 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);
@ -207,6 +207,9 @@ private static readonly Regex ShadowRegex = new Regex(@"shadow-true", RegexOptio
// Set the hinting and draw the text.
graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
// Create bounds for the text.
RectangleF bounds;
if (textLayer.DropShadow)
{
// Shadow opacity should change with the base opacity.
@ -219,11 +222,18 @@ private static readonly Regex ShadowRegex = new Regex(@"shadow-true", RegexOptio
// Magic number but it's based on artistic preference.
int shadowDiff = (int)Math.Ceiling(fontSize / 24f);
Point shadowPoint = new Point(origin.X + shadowDiff, origin.Y + shadowDiff);
graphics.DrawString(text, font, shadowBrush, shadowPoint, drawFormat);
// Set the bounds so any overlapping text will wrap.
bounds = new RectangleF(shadowPoint, new SizeF(image.Width - shadowPoint.X, image.Height - shadowPoint.Y));
graphics.DrawString(text, font, shadowBrush, bounds, drawFormat);
}
}
graphics.DrawString(text, font, brush, origin, drawFormat);
// Set the bounds so any overlapping text will wrap.
bounds = new RectangleF(origin, new SizeF(image.Width - origin.X, image.Height - origin.Y));
graphics.DrawString(text, font, brush, bounds, drawFormat);
}
}
}

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.7.0.1")]
[assembly: AssemblyFileVersion("1.7.0.1")]
[assembly: AssemblyVersion("1.7.0.2")]
[assembly: AssemblyFileVersion("1.7.0.2")]

BIN
src/Nuget/ImageProcessor.1.7.0.2.nupkg

Binary file not shown.

4
src/Nuget/imageprocessor.128.png

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:594e72bfc3c1804871e083684e8927f92b9619c5b42855b8a530556ce037d356
size 5724
oid sha256:d4e936585d0857f7c38a3c70e9dd5d2414a84af39db30b0be698bc151d7a9225
size 6510

2
src/TestWebsites/NET45/Test_Website_NET45/Views/Home/Index.cshtml

@ -70,7 +70,7 @@
<div class="row">
<div class="column-6">
<h2>Watermark</h2>
<img src="/images/Penguins.jpg?width=300&watermark=text-test|color-fff|size-48|style-italic|opacity-100|position-100-100|shadow-true|font-arial" />
<img src="/images/Penguins.jpg?width=300&watermark=text-This+is+a+long+body+of+copy+that+should+wrap|color-fff|size-24|style-italic|opacity-100|position-100-100|shadow-true|font-arial" />
</div>
<div class="column-6">
<h2>Format</h2>

Loading…
Cancel
Save