Skip to content

Commit 28c91e4

Browse files
committed
Moved Crop to IMagickImageCreateOperations.
1 parent 1ac655b commit 28c91e4

File tree

6 files changed

+84
-44
lines changed

6 files changed

+84
-44
lines changed

src/Magick.NET.Core/IMagickImage.cs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -853,42 +853,6 @@ public partial interface IMagickImage : IMagickImageCreateOperations, IDisposabl
853853
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
854854
void CopyPixels(IMagickImage source, IMagickGeometry geometry, int x, int y, Channels channels);
855855

856-
/// <summary>
857-
/// Crop image (subregion of original image). <see cref="ResetPage"/> should be called unless
858-
/// the <see cref="Page"/> information is needed.
859-
/// </summary>
860-
/// <param name="width">The width of the subregion to crop.</param>
861-
/// <param name="height">The height of the subregion to crop.</param>
862-
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
863-
void Crop(uint width, uint height);
864-
865-
/// <summary>
866-
/// Crop image (subregion of original image). <see cref="ResetPage"/> should be called unless
867-
/// the <see cref="Page"/> information is needed.
868-
/// </summary>
869-
/// <param name="width">The width of the subregion to crop.</param>
870-
/// <param name="height">The height of the subregion to crop.</param>
871-
/// <param name="gravity">The position where the cropping should start from.</param>
872-
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
873-
void Crop(uint width, uint height, Gravity gravity);
874-
875-
/// <summary>
876-
/// Crop image (subregion of original image). <see cref="ResetPage"/> should be called unless
877-
/// the <see cref="Page"/> information is needed.
878-
/// </summary>
879-
/// <param name="geometry">The subregion to crop.</param>
880-
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
881-
void Crop(IMagickGeometry geometry);
882-
883-
/// <summary>
884-
/// Crop image (subregion of original image). <see cref="ResetPage"/> should be called unless
885-
/// the <see cref="Page"/> information is needed.
886-
/// </summary>
887-
/// <param name="geometry">The subregion to crop.</param>
888-
/// <param name="gravity">The position where the cropping should start from.</param>
889-
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
890-
void Crop(IMagickGeometry geometry, Gravity gravity);
891-
892856
/// <summary>
893857
/// Displaces an image's colormap by a given number of positions.
894858
/// </summary>

src/Magick.NET.Core/IMagickImageCreateOperations.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,42 @@ public interface IMagickImageCreateOperations
342342
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
343343
void Convolve(IConvolveMatrix matrix);
344344

345+
/// <summary>
346+
/// Crop image (subregion of original image). <see cref="IMagickImage.ResetPage"/> should be called unless
347+
/// the <see cref="IMagickImage.Page"/> information is needed.
348+
/// </summary>
349+
/// <param name="width">The width of the subregion to crop.</param>
350+
/// <param name="height">The height of the subregion to crop.</param>
351+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
352+
void Crop(uint width, uint height);
353+
354+
/// <summary>
355+
/// Crop image (subregion of original image). <see cref="IMagickImage.ResetPage"/> should be called unless
356+
/// the <see cref="Page"/> information is needed.
357+
/// </summary>
358+
/// <param name="width">The width of the subregion to crop.</param>
359+
/// <param name="height">The height of the subregion to crop.</param>
360+
/// <param name="gravity">The position where the cropping should start from.</param>
361+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
362+
void Crop(uint width, uint height, Gravity gravity);
363+
364+
/// <summary>
365+
/// Crop image (subregion of original image). <see cref="IMagickImage.ResetPage"/> should be called unless
366+
/// the <see cref="IMagickImage.Page"/> information is needed.
367+
/// </summary>
368+
/// <param name="geometry">The subregion to crop.</param>
369+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
370+
void Crop(IMagickGeometry geometry);
371+
372+
/// <summary>
373+
/// Crop image (subregion of original image). <see cref="IMagickImage.ResetPage"/> should be called unless
374+
/// the <see cref="IMagickImage.Page"/> information is needed.
375+
/// </summary>
376+
/// <param name="geometry">The subregion to crop.</param>
377+
/// <param name="gravity">The position where the cropping should start from.</param>
378+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
379+
void Crop(IMagickGeometry geometry, Gravity gravity);
380+
345381
/// <summary>
346382
/// Resize image to specified size.
347383
/// <para />

src/Magick.NET/MagickImage.CloneMutator.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,22 @@ public void Convolve(IConvolveMatrix matrix)
206206
SetResult(NativeMagickImage.Convolve(matrix));
207207
}
208208

209+
public void Crop(uint width, uint height)
210+
=> Crop(width, height, Gravity.Undefined);
211+
212+
public void Crop(uint width, uint height, Gravity gravity)
213+
=> Crop(new MagickGeometry(0, 0, width, height), gravity);
214+
215+
public void Crop(IMagickGeometry geometry)
216+
=> Crop(geometry, Gravity.Undefined);
217+
218+
public void Crop(IMagickGeometry geometry, Gravity gravity)
219+
{
220+
Throw.IfNull(nameof(geometry), geometry);
221+
222+
SetResult(NativeMagickImage.Crop(geometry.ToString(), gravity));
223+
}
224+
209225
public void Resize(uint width, uint height)
210226
=> Resize(new MagickGeometry(width, height));
211227

src/Magick.NET/MagickImage.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,7 +2424,10 @@ public void CopyPixels(IMagickImage source, IMagickGeometry geometry, int x, int
24242424
/// <param name="height">The height of the subregion to crop.</param>
24252425
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
24262426
public void Crop(uint width, uint height)
2427-
=> Crop(width, height, Gravity.Undefined);
2427+
{
2428+
using var mutator = new Mutator(_nativeInstance);
2429+
mutator.Crop(width, height);
2430+
}
24282431

24292432
/// <summary>
24302433
/// Crop image (subregion of original image). <see cref="ResetPage"/> should be called unless
@@ -2435,7 +2438,10 @@ public void Crop(uint width, uint height)
24352438
/// <param name="gravity">The position where the cropping should start from.</param>
24362439
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
24372440
public void Crop(uint width, uint height, Gravity gravity)
2438-
=> Crop(new MagickGeometry(0, 0, width, height), gravity);
2441+
{
2442+
using var mutator = new Mutator(_nativeInstance);
2443+
mutator.Crop(width, height, gravity);
2444+
}
24392445

24402446
/// <summary>
24412447
/// Crop image (subregion of original image). <see cref="ResetPage"/> should be called unless
@@ -2444,7 +2450,10 @@ public void Crop(uint width, uint height, Gravity gravity)
24442450
/// <param name="geometry">The subregion to crop.</param>
24452451
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
24462452
public void Crop(IMagickGeometry geometry)
2447-
=> Crop(geometry, Gravity.Undefined);
2453+
{
2454+
using var mutator = new Mutator(_nativeInstance);
2455+
mutator.Crop(geometry);
2456+
}
24482457

24492458
/// <summary>
24502459
/// Crop image (subregion of original image). <see cref="ResetPage"/> should be called unless
@@ -2455,9 +2464,8 @@ public void Crop(IMagickGeometry geometry)
24552464
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
24562465
public void Crop(IMagickGeometry geometry, Gravity gravity)
24572466
{
2458-
Throw.IfNull(nameof(geometry), geometry);
2459-
2460-
_nativeInstance.Crop(geometry.ToString(), gravity);
2467+
using var mutator = new Mutator(_nativeInstance);
2468+
mutator.Crop(geometry, gravity);
24612469
}
24622470

24632471
/// <summary>

src/Magick.NET/Native/MagickImage.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,7 @@ private unsafe sealed partial class NativeMagickImage : NativeInstance, INativeM
353353
public partial void CopyPixels(IMagickImage image, MagickRectangle geometry, OffsetInfo offset, Channels channels);
354354

355355
[Throws]
356-
[SetInstance]
357-
public partial void Crop(string geometry, Gravity gravity);
356+
public partial IntPtr Crop(string geometry, Gravity gravity);
358357

359358
[Throws]
360359
public partial IntPtr CropToTiles(string geometry);

tests/Magick.NET.Tests/TestIssue.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,22 @@ public class TestIssue
1818
[Fact]
1919
public void RunTest()
2020
{
21+
var drawables = new Drawables();
22+
23+
drawables.FontPointSize(40)
24+
.Font(@"I:\issues\im7\1752\font1.ttf")
25+
.FillColor(MagickColors.Black)
26+
.TextAlignment(TextAlignment.Left)
27+
.Text(100, 50, "This is such a nice font!");
28+
29+
drawables.FontPointSize(40)
30+
.Font(@"I:\issues\im7\1752\font2.ttf")
31+
.FillColor(MagickColors.Black)
32+
.TextAlignment(TextAlignment.Left)
33+
.Text(100, 100, "This is even better, or does it look the same?");
34+
35+
using var image = new MagickImage(MagickColors.White, 1000, 800);
36+
drawables.Draw(image);
37+
image.Write(@"I:\issues\im7\1752\z.png");
2138
}
2239
}

0 commit comments

Comments
 (0)