Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static (Size, Rectangle) CalculateTargetLocationAndBounds(Size sourceSize

// case ResizeMode.Stretch:
default:
return (new Size(width, height), new Rectangle(0, 0, width, height));
return (new Size(Sanitize(width), Sanitize(height)), new Rectangle(0, 0, width, height));
Comment thread
dlemstra marked this conversation as resolved.
Outdated
}
}

Expand Down Expand Up @@ -143,7 +143,7 @@ private static (Size, Rectangle) CalculateBoxPadRectangle(
}

// Target image width and height can be different to the rectangle width and height.
return (new Size(width, height), new Rectangle(targetX, targetY, targetWidth, targetHeight));
return (new Size(Sanitize(width), Sanitize(height)), new Rectangle(targetX, targetY, Sanitize(targetWidth), Sanitize(targetHeight)));
}

// Switch to pad mode to downscale and calculate from there.
Expand Down Expand Up @@ -253,7 +253,7 @@ private static (Size, Rectangle) CalculateCropRectangle(
}

// Target image width and height can be different to the rectangle width and height.
return (new Size(width, height), new Rectangle(targetX, targetY, targetWidth, targetHeight));
return (new Size(Sanitize(width), Sanitize(height)), new Rectangle(targetX, targetY, Sanitize(targetWidth), Sanitize(targetHeight)));
}

private static (Size, Rectangle) CalculateMaxRectangle(
Expand Down Expand Up @@ -282,7 +282,7 @@ private static (Size, Rectangle) CalculateMaxRectangle(
}

// Replace the size to match the rectangle.
return (new Size(targetWidth, targetHeight), new Rectangle(0, 0, targetWidth, targetHeight));
return (new Size(Sanitize(targetWidth), Sanitize(targetHeight)), new Rectangle(0, 0, Sanitize(targetWidth), Sanitize(targetHeight)));
}

private static (Size, Rectangle) CalculateMinRectangle(
Expand Down Expand Up @@ -330,7 +330,7 @@ private static (Size, Rectangle) CalculateMinRectangle(
}

// Replace the size to match the rectangle.
return (new Size(targetWidth, targetHeight), new Rectangle(0, 0, targetWidth, targetHeight));
return (new Size(Sanitize(targetWidth), Sanitize(targetHeight)), new Rectangle(0, 0, Sanitize(targetWidth), Sanitize(targetHeight)));
}

private static (Size, Rectangle) CalculatePadRectangle(
Expand Down Expand Up @@ -398,7 +398,7 @@ private static (Size, Rectangle) CalculatePadRectangle(
}

// Target image width and height can be different to the rectangle width and height.
return (new Size(width, height), new Rectangle(targetX, targetY, targetWidth, targetHeight));
return (new Size(Sanitize(width), Sanitize(height)), new Rectangle(targetX, targetY, Sanitize(targetWidth), Sanitize(targetHeight)));
}

private static (Size, Rectangle) CalculateManualRectangle(
Expand All @@ -419,9 +419,14 @@ private static (Size, Rectangle) CalculateManualRectangle(
int targetHeight = targetRectangle.Height > 0 ? targetRectangle.Height : height;

// Target image width and height can be different to the rectangle width and height.
return (new Size(width, height), new Rectangle(targetX, targetY, targetWidth, targetHeight));
return (new Size(Sanitize(width), Sanitize(height)), new Rectangle(targetX, targetY, Sanitize(targetWidth), Sanitize(targetHeight)));
}

private static void ThrowInvalid(string message) => throw new InvalidOperationException(message);

private static int Sanitize(int input)

@dlemstra dlemstra May 9, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking but this could be an arrow.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm usually not precious, updated now though

{
return Math.Max(1, input);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -605,5 +605,21 @@ public void CanResizeExifIssueImages<TPixel>(TestImageProvider<TPixel> provider)
image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2));
}
}

[Fact]
public void Issue1195()
{
using (var image = new Image<Rgba32>(2, 300))
{
var size = new Size(50, 50);
image.Mutate(x => x
.Resize(
new ResizeOptions
{
Size = size,
Mode = ResizeMode.Max
}));
}
}
}
}