diff --git a/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs b/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs index e2aca1d90..031bcbdf7 100644 --- a/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs +++ b/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs @@ -96,19 +96,9 @@ internal class DrawImageProcessor : ImageProcessor top = 0; } - if (left > source.Width - foregroundRectangle.Width) - { - // will overhange, lets trim it down - int diff = (left + foregroundRectangle.Width) - source.Width; - foregroundRectangle.Width -= diff; - } - - if (top > source.Height - foregroundRectangle.Height) - { - // will overhange, lets trim it down - int diff = (top + foregroundRectangle.Height) - source.Height; - foregroundRectangle.Height -= diff; - } + // clamp the height/width to the availible space left to prevent overflowing + foregroundRectangle.Width = Math.Min(source.Width - left, foregroundRectangle.Width); + foregroundRectangle.Height = Math.Min(source.Height - top, foregroundRectangle.Height); int width = foregroundRectangle.Width; int height = foregroundRectangle.Height;