Browse Source

Merge remote-tracking branch 'origin/dev'

Conflicts:
	src/ImageProcessor.Web/NET45/Properties/AssemblyInfo.cs

Former-commit-id: b656218217af84697fc1fb400c611ebc9d3b6c1b
af/merge-core
James South 12 years ago
parent
commit
d1909a2159
  1. 6
      src/ImageProcessor/Imaging/ResizeLayer.cs
  2. 115
      src/ImageProcessor/Processors/Resize.cs
  3. 4
      src/ImageProcessor/Properties/AssemblyInfo.cs
  4. 1
      src/Nuget/ImageProcessor.1.8.4.0.nupkg.REMOVED.git-id
  5. 4
      src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config

6
src/ImageProcessor/Imaging/ResizeLayer.cs

@ -79,6 +79,12 @@ namespace ImageProcessor.Imaging
/// Gets or sets a value indicating whether to allow up-scaling of images.
/// </summary>
public bool Upscale { get; set; }
/// <summary>
/// Gets or sets the center coordinates.
/// </summary>
public float[] CenterCoordinates { get; set; }
#endregion
/// <summary>

115
src/ImageProcessor/Processors/Resize.cs

@ -34,7 +34,7 @@ namespace ImageProcessor.Processors
/// <summary>
/// The regular expression to search strings for.
/// </summary>
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);
private static readonly Regex QueryRegex = new Regex(@"((width|height)=\d+)|(mode=(pad|stretch|crop|max))|(anchor=(top|bottom|left|right|center))|(center=\d+(.\d+)?[,-]\d+(.\d+))|(bgcolor=(transparent|\d+,\d+,\d+,\d+|([0-9a-fA-F]{3}){1,2}))|(upscale=false)", RegexOptions.Compiled);
/// <summary>
/// The regular expression to search strings for the size attribute.
@ -51,6 +51,11 @@ namespace ImageProcessor.Processors
/// </summary>
private static readonly Regex AnchorRegex = new Regex(@"anchor=(top|bottom|left|right|center)", RegexOptions.Compiled);
/// <summary>
/// The regular expression to search strings for the center attribute.
/// </summary>
private static readonly Regex CenterRegex = new Regex(@"center=\d+(.\d+)?[,-]\d+(.\d+)", RegexOptions.Compiled);
/// <summary>
/// The regular expression to search strings for the color attribute.
/// </summary>
@ -144,10 +149,12 @@ namespace ImageProcessor.Processors
ResizeMode = this.ParseMode(toParse),
AnchorPosition = this.ParsePosition(toParse),
BackgroundColor = this.ParseColor(toParse),
Upscale = !UpscaleRegex.IsMatch(toParse)
Upscale = !UpscaleRegex.IsMatch(toParse),
};
resizeLayer.CenterCoordinates = this.ParseCoordinates(toParse);
this.DynamicParameter = resizeLayer;
return this.SortOrder;
}
@ -169,6 +176,7 @@ namespace ImageProcessor.Processors
AnchorPosition anchor = this.DynamicParameter.AnchorPosition;
Color backgroundColor = this.DynamicParameter.BackgroundColor;
bool upscale = this.DynamicParameter.Upscale;
float[] centerCoordinates = this.DynamicParameter.CenterCoordinates;
int defaultMaxWidth;
int defaultMaxHeight;
@ -178,7 +186,8 @@ namespace ImageProcessor.Processors
int.TryParse(this.Settings["MaxHeight"], out defaultMaxHeight);
List<Size> restrictedSizes = this.ParseRestrictions(restrictions);
return this.ResizeImage(factory, width, height, defaultMaxWidth, defaultMaxHeight, restrictedSizes, backgroundColor, mode, anchor, upscale);
return this.ResizeImage(factory, width, height, defaultMaxWidth, defaultMaxHeight, restrictedSizes, backgroundColor, mode, anchor, upscale, centerCoordinates);
}
#endregion
@ -216,6 +225,9 @@ namespace ImageProcessor.Processors
/// <param name="upscale">
/// Whether to allow up-scaling of images. (Default true)
/// </param>
/// <param name="centerCoordinates">
/// If the resize mode is crop, you can set a specific center coordinate, use as alternative to anchorPosition
/// </param>
/// <returns>
/// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
/// </returns>
@ -229,7 +241,8 @@ namespace ImageProcessor.Processors
Color backgroundColor,
ResizeMode resizeMode = ResizeMode.Pad,
AnchorPosition anchorPosition = AnchorPosition.Center,
bool upscale = true)
bool upscale = true,
float[] centerCoordinates = null)
{
Bitmap newImage = null;
Image image = factory.Image;
@ -282,17 +295,35 @@ namespace ImageProcessor.Processors
{
ratio = percentWidth;
switch (anchorPosition)
if (centerCoordinates != null && centerCoordinates.Any())
{
case AnchorPosition.Top:
double center = -(ratio * sourceHeight) * centerCoordinates[0];
destinationY = (int)center + (height / 2);
if (destinationY > 0)
{
destinationY = 0;
break;
case AnchorPosition.Bottom:
}
if (destinationY < (int)(height - (sourceHeight * ratio)))
{
destinationY = (int)(height - (sourceHeight * ratio));
break;
default:
destinationY = (int)((height - (sourceHeight * ratio)) / 2);
break;
}
}
else
{
switch (anchorPosition)
{
case AnchorPosition.Top:
destinationY = 0;
break;
case AnchorPosition.Bottom:
destinationY = (int)(height - (sourceHeight * ratio));
break;
default:
destinationY = (int)((height - (sourceHeight * ratio)) / 2);
break;
}
}
destinationHeight = (int)Math.Ceiling(sourceHeight * percentWidth);
@ -301,17 +332,35 @@ namespace ImageProcessor.Processors
{
ratio = percentHeight;
switch (anchorPosition)
if (centerCoordinates != null && centerCoordinates.Any())
{
case AnchorPosition.Left:
double center = -(ratio * sourceWidth) * centerCoordinates[1];
destinationX = (int)center + (width / 2);
if (destinationX > 0)
{
destinationX = 0;
break;
case AnchorPosition.Right:
}
if (destinationX < (int)(width - (sourceWidth * ratio)))
{
destinationX = (int)(width - (sourceWidth * ratio));
break;
default:
destinationX = (int)((width - (sourceWidth * ratio)) / 2);
break;
}
}
else
{
switch (anchorPosition)
{
case AnchorPosition.Left:
destinationX = 0;
break;
case AnchorPosition.Right:
destinationX = (int)(width - (sourceWidth * ratio));
break;
default:
destinationX = (int)((width - (sourceWidth * ratio)) / 2);
break;
}
}
destinationWidth = (int)Math.Ceiling(sourceWidth * percentHeight);
@ -356,7 +405,14 @@ namespace ImageProcessor.Processors
bool reject = true;
foreach (Size restrictedSize in restrictedSizes)
{
if (restrictedSize.Width == width && restrictedSize.Height == height)
if (restrictedSize.Height == 0 || restrictedSize.Width == 0)
{
if (restrictedSize.Width == width || restrictedSize.Height == height)
{
reject = false;
}
}
else if (restrictedSize.Width == width && restrictedSize.Height == height)
{
reject = false;
}
@ -602,5 +658,22 @@ namespace ImageProcessor.Processors
return sizes;
}
/// <summary>
/// Parses the coordinates.
/// </summary>
/// <param name="input">The input.</param>
/// <returns>The <see cref="float"/> array containing the coordinates</returns>
private float[] ParseCoordinates(string input)
{
float[] floats = { };
foreach (Match match in CenterRegex.Matches(input))
{
floats = match.Value.ToPositiveFloatArray();
}
return floats;
}
}
}

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.8.3.0")]
[assembly: AssemblyFileVersion("1.8.3.0")]
[assembly: AssemblyVersion("1.8.4.0")]
[assembly: AssemblyFileVersion("1.8.4.0")]

1
src/Nuget/ImageProcessor.1.8.4.0.nupkg.REMOVED.git-id

@ -0,0 +1 @@
effc95273383a6d336dd589cf684b3952cb98699

4
src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<processing>
<presets>
<!--<preset name="demo" value="width=300&#038;height=150&#038;bgcolor=transparent"/>-->
<preset name="demo" value="width=300&#038;height=150&#038;bgcolor=transparent"/>
</presets>
<plugins autoLoadPlugins="true">
<plugin name="Alpha" type="ImageProcessor.Processors.Alpha, ImageProcessor"/>
@ -30,7 +30,7 @@
<settings>
<setting key="MaxWidth" value="3000"/>
<setting key="MaxHeight" value="3000"/>
<!--<setting key="RestrictTo" value="width=300height=300,width=300height=300"/>-->
<setting key="RestrictTo" value="width=300"/>
</settings>
</plugin>
<plugin name="Rotate" type="ImageProcessor.Processors.Rotate, ImageProcessor"/>

Loading…
Cancel
Save