From 8bd1e0361269d4851a40f1be10bbe1a55516c6cf Mon Sep 17 00:00:00 2001 From: Dmitry Kovsh Date: Sat, 6 Sep 2014 01:45:55 +0300 Subject: [PATCH] Adding possibility of cropping the image to the specified rectangle on the source image. --- .../ResizeExpression.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 ///