File tree Expand file tree Collapse file tree
src/ImageSharp/Processing/Processors/Drawing Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -96,19 +96,9 @@ protected override void OnFrameApply(ImageFrame<TPixelBg> source)
9696 top = 0 ;
9797 }
9898
99- if ( left > source . Width - foregroundRectangle . Width )
100- {
101- // will overhange, lets trim it down
102- int diff = ( left + foregroundRectangle . Width ) - source . Width ;
103- foregroundRectangle . Width -= diff ;
104- }
105-
106- if ( top > source . Height - foregroundRectangle . Height )
107- {
108- // will overhange, lets trim it down
109- int diff = ( top + foregroundRectangle . Height ) - source . Height ;
110- foregroundRectangle . Height -= diff ;
111- }
99+ // clamp the height/width to the availible space left to prevent overflowing
100+ foregroundRectangle . Width = Math . Min ( source . Width - left , foregroundRectangle . Width ) ;
101+ foregroundRectangle . Height = Math . Min ( source . Height - top , foregroundRectangle . Height ) ;
112102
113103 int width = foregroundRectangle . Width ;
114104 int height = foregroundRectangle . Height ;
You can’t perform that action at this time.
0 commit comments