Browse Source

Resize.Web now accepts and parses decimal values.

Former-commit-id: 5a67262c314cadabaac51b6e4166b807bf4f93da
pull/17/head
James South 12 years ago
parent
commit
a545cc37b4
  1. 16
      src/ImageProcessor.Web/Processors/Resize.cs
  2. 12
      src/ImageProcessor/Processors/Resize.cs

16
src/ImageProcessor.Web/Processors/Resize.cs

@ -34,7 +34,7 @@ namespace ImageProcessor.Web.Processors
/// <summary> /// <summary>
/// The regular expression to search strings for the size attribute. /// The regular expression to search strings for the size attribute.
/// </summary> /// </summary>
private static readonly Regex SizeRegex = new Regex(@"(width|height)=\d+", RegexOptions.Compiled); private static readonly Regex SizeRegex = new Regex(@"(width|height)=\d+(.\d+)?", RegexOptions.Compiled);
/// <summary> /// <summary>
/// The regular expression to search strings for the ratio attribute. /// The regular expression to search strings for the ratio attribute.
@ -178,23 +178,23 @@ namespace ImageProcessor.Web.Processors
if (input.Contains(Width) && !input.Contains(Height)) if (input.Contains(Width) && !input.Contains(Height))
{ {
size = new Size(value.ToPositiveIntegerArray()[0], 0); size = new Size(Convert.ToInt32(value.ToPositiveFloatArray()[0]), 0);
} }
if (input.Contains(Height) && !input.Contains(Width)) if (input.Contains(Height) && !input.Contains(Width))
{ {
size = new Size(0, value.ToPositiveIntegerArray()[0]); size = new Size(0, Convert.ToInt32(value.ToPositiveFloatArray()[0]));
} }
// Both dimensions supplied. // Both dimensions supplied.
if (input.Contains(Height) && input.Contains(Width)) if (input.Contains(Height) && input.Contains(Width))
{ {
int[] dimensions = value.ToPositiveIntegerArray(); float[] dimensions = value.ToPositiveFloatArray();
// Check the order in which they have been supplied. // Check the order in which they have been supplied.
size = input.IndexOf(Width, StringComparison.Ordinal) < input.IndexOf(Height, StringComparison.Ordinal) size = input.IndexOf(Width, StringComparison.Ordinal) < input.IndexOf(Height, StringComparison.Ordinal)
? new Size(dimensions[0], dimensions[1]) ? new Size(Convert.ToInt32(dimensions[0]), Convert.ToInt32(dimensions[1]))
: new Size(dimensions[1], dimensions[0]); : new Size(Convert.ToInt32(dimensions[1]), Convert.ToInt32(dimensions[0]));
} }
// Calculate any ratio driven sizes. // Calculate any ratio driven sizes.
@ -211,13 +211,13 @@ namespace ImageProcessor.Web.Processors
// Replace 0 width // Replace 0 width
if (size.Width == 0 && size.Height > 0 && input.Contains(WidthRatio) && !input.Contains(HeightRatio)) if (size.Width == 0 && size.Height > 0 && input.Contains(WidthRatio) && !input.Contains(HeightRatio))
{ {
size.Width = (int)Math.Ceiling(value.ToPositiveFloatArray()[0] * size.Height); size.Width = Convert.ToInt32(value.ToPositiveFloatArray()[0] * size.Height);
} }
// Replace 0 height // Replace 0 height
if (size.Height == 0 && size.Width > 0 && input.Contains(HeightRatio) && !input.Contains(WidthRatio)) if (size.Height == 0 && size.Width > 0 && input.Contains(HeightRatio) && !input.Contains(WidthRatio))
{ {
size.Height = (int)Math.Ceiling(value.ToPositiveFloatArray()[0] * size.Width); size.Height = Convert.ToInt32(value.ToPositiveFloatArray()[0] * size.Width);
} }
} }

12
src/ImageProcessor/Processors/Resize.cs

@ -164,14 +164,14 @@ namespace ImageProcessor.Processors
if (percentHeight < percentWidth) if (percentHeight < percentWidth)
{ {
ratio = percentHeight; ratio = percentHeight;
destinationX = (int)((width - (sourceWidth * ratio)) / 2); destinationX = Convert.ToInt32((width - (sourceWidth * ratio)) / 2);
destinationWidth = (int)Math.Ceiling(sourceWidth * percentHeight); destinationWidth = Convert.ToInt32(sourceWidth * percentHeight);
} }
else else
{ {
ratio = percentWidth; ratio = percentWidth;
destinationY = (int)((height - (sourceHeight * ratio)) / 2); destinationY = Convert.ToInt32((height - (sourceHeight * ratio)) / 2);
destinationHeight = (int)Math.Ceiling(sourceHeight * percentWidth); destinationHeight = Convert.ToInt32(sourceHeight * percentWidth);
} }
} }
@ -281,13 +281,13 @@ namespace ImageProcessor.Processors
// If height or width is not passed we assume that the standard ratio is to be kept. // If height or width is not passed we assume that the standard ratio is to be kept.
if (height == 0) if (height == 0)
{ {
destinationHeight = (int)Math.Ceiling(sourceHeight * percentWidth); destinationHeight = Convert.ToInt32(sourceHeight * percentWidth);
height = destinationHeight; height = destinationHeight;
} }
if (width == 0) if (width == 0)
{ {
destinationWidth = (int)Math.Ceiling(sourceWidth * percentHeight); destinationHeight = Convert.ToInt32(sourceHeight * percentWidth);
width = destinationWidth; width = destinationWidth;
} }

Loading…
Cancel
Save