diff --git a/src/ImageResizer.FluentExtensions/ResizeExpression.cs b/src/ImageResizer.FluentExtensions/ResizeExpression.cs index f76bf77..c4a72e8 100644 --- a/src/ImageResizer.FluentExtensions/ResizeExpression.cs +++ b/src/ImageResizer.FluentExtensions/ResizeExpression.cs @@ -97,6 +97,25 @@ public AlignmentExpression Crop() return new AlignmentExpression(this.builder); } + /// + /// Crop the image to the specified rectangle on the source image. + /// + /// x coordinate of the top-left corner of the original image. + /// y coordinate of the top-left corner of the original image. + /// x coordinate of the bottom-right corner of the original image. + /// y coordinate of the bottom-right corner of the original image. + public AlignmentExpression Crop(int x1, int y1, int x2, int y2) + { + if (x1 >= x2) + throw new ArgumentException("x1 must be greater than x2."); + + if (y1 >= y2) + throw new ArgumentException("y1 must be greater than y2."); + + builder.SetParameter(ResizeCommands.FitModeCrop, string.Format("{0},{1},{2},{3}", x1, y1, x2, y2)); + return new AlignmentExpression(this.builder); + } + /// /// Sets the fit mode to Stretch. Stretches the image, losing aspect ratio ///