Skip to content

Commit ec4077b

Browse files
committed
Added extra overload to the resize method that allows specifying the filter (#1819).
1 parent 782a782 commit ec4077b

File tree

4 files changed

+158
-8
lines changed

4 files changed

+158
-8
lines changed

src/Magick.NET.Core/IMagickImageCreateOperations.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,13 +768,30 @@ public interface IMagickImageCreateOperations
768768
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
769769
void Resample(double resolutionX, double resolutionY);
770770

771+
/// <summary>
772+
/// Resize image in terms of its pixel size.
773+
/// </summary>
774+
/// <param name="resolutionX">The new X resolution.</param>
775+
/// <param name="resolutionY">The new Y resolution.</param>
776+
/// <param name="filter">The filter to use.</param>
777+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
778+
void Resample(double resolutionX, double resolutionY, FilterType filter);
779+
771780
/// <summary>
772781
/// Resize image in terms of its pixel size.
773782
/// </summary>
774783
/// <param name="density">The density to use.</param>
775784
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
776785
void Resample(PointD density);
777786

787+
/// <summary>
788+
/// Resize image in terms of its pixel size.
789+
/// </summary>
790+
/// <param name="density">The density to use.</param>
791+
/// <param name="filter">The filter to use.</param>
792+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
793+
void Resample(PointD density, FilterType filter);
794+
778795
/// <summary>
779796
/// Resize image to specified size.
780797
/// <para />
@@ -786,20 +803,48 @@ public interface IMagickImageCreateOperations
786803
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
787804
void Resize(uint width, uint height);
788805

806+
/// <summary>
807+
/// Resize image to specified size.
808+
/// <para />
809+
/// Resize will fit the image into the requested size. It does NOT fill, the requested box size.
810+
/// Use the <see cref="IMagickGeometry"/> overload for more control over the resulting size.
811+
/// </summary>
812+
/// <param name="width">The new width.</param>
813+
/// <param name="height">The new height.</param>
814+
/// <param name="filter">The filter to use.</param>
815+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
816+
void Resize(uint width, uint height, FilterType filter);
817+
789818
/// <summary>
790819
/// Resize image to specified geometry.
791820
/// </summary>
792821
/// <param name="geometry">The geometry to use.</param>
793822
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
794823
void Resize(IMagickGeometry geometry);
795824

825+
/// <summary>
826+
/// Resize image to specified geometry.
827+
/// </summary>
828+
/// <param name="geometry">The geometry to use.</param>
829+
/// <param name="filter">The filter to use.</param>
830+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
831+
void Resize(IMagickGeometry geometry, FilterType filter);
832+
796833
/// <summary>
797834
/// Resize image to specified percentage.
798835
/// </summary>
799836
/// <param name="percentage">The percentage.</param>
800837
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
801838
void Resize(Percentage percentage);
802839

840+
/// <summary>
841+
/// Resize image to specified percentage.
842+
/// </summary>
843+
/// <param name="percentage">The percentage.</param>
844+
/// <param name="filter">The filter to use.</param>
845+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
846+
void Resize(Percentage percentage, FilterType filter);
847+
803848
/// <summary>
804849
/// Resize image to specified percentage.
805850
/// </summary>
@@ -808,6 +853,15 @@ public interface IMagickImageCreateOperations
808853
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
809854
void Resize(Percentage percentageWidth, Percentage percentageHeight);
810855

856+
/// <summary>
857+
/// Resize image to specified percentage.
858+
/// </summary>
859+
/// <param name="percentageWidth">The percentage of the width.</param>
860+
/// <param name="percentageHeight">The percentage of the height.</param>
861+
/// <param name="filter">The filter to use.</param>
862+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
863+
void Resize(Percentage percentageWidth, Percentage percentageHeight, FilterType filter);
864+
811865
/// <summary>
812866
/// Roll image (rolls image vertically and horizontally).
813867
/// </summary>

src/Magick.NET/MagickImage.CloneMutator.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -439,26 +439,44 @@ public void OilPaint(double radius, double sigma)
439439
=> SetResult(NativeMagickImage.OilPaint(radius, sigma));
440440

441441
public void Resample(double resolutionX, double resolutionY)
442-
=> SetResult(NativeMagickImage.Resample(resolutionX, resolutionY));
442+
=> Resample(resolutionX, resolutionY, NativeMagickImage.FilterType_Get());
443+
444+
public void Resample(double resolutionX, double resolutionY, FilterType filter)
445+
=> SetResult(NativeMagickImage.Resample(resolutionX, resolutionY, filter));
443446

444447
public void Resample(PointD density)
445-
=> Resample(density.X, density.Y);
448+
=> Resample(density, NativeMagickImage.FilterType_Get());
449+
450+
public void Resample(PointD density, FilterType filter)
451+
=> Resample(density.X, density.Y, filter);
446452

447453
public void Resize(uint width, uint height)
448-
=> Resize(new MagickGeometry(width, height));
454+
=> Resize(width, height, NativeMagickImage.FilterType_Get());
455+
456+
public void Resize(uint width, uint height, FilterType filter)
457+
=> Resize(new MagickGeometry(width, height), filter);
449458

450459
public void Resize(IMagickGeometry geometry)
460+
=> Resize(geometry, NativeMagickImage.FilterType_Get());
461+
462+
public void Resize(IMagickGeometry geometry, FilterType filter)
451463
{
452464
Throw.IfNull(geometry);
453465

454-
SetResult(NativeMagickImage.Resize(geometry.ToString()));
466+
SetResult(NativeMagickImage.Resize(geometry.ToString(), filter));
455467
}
456468

457469
public void Resize(Percentage percentage)
458-
=> Resize(new MagickGeometry(percentage, percentage));
470+
=> Resize(percentage, NativeMagickImage.FilterType_Get());
471+
472+
public void Resize(Percentage percentage, FilterType filter)
473+
=> Resize(new MagickGeometry(percentage, percentage), filter);
459474

460475
public void Resize(Percentage percentageWidth, Percentage percentageHeight)
461-
=> Resize(new MagickGeometry(percentageWidth, percentageHeight));
476+
=> Resize(percentageWidth, percentageHeight, NativeMagickImage.FilterType_Get());
477+
478+
public void Resize(Percentage percentageWidth, Percentage percentageHeight, FilterType filter)
479+
=> Resize(new MagickGeometry(percentageWidth, percentageHeight), filter);
462480

463481
public void Roll(int x, int y)
464482
=> SetResult(NativeMagickImage.Roll(x, y));

src/Magick.NET/MagickImage.cs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5396,6 +5396,19 @@ public void Resample(double resolutionX, double resolutionY)
53965396
mutator.Resample(resolutionX, resolutionY);
53975397
}
53985398

5399+
/// <summary>
5400+
/// Resize image in terms of its pixel size.
5401+
/// </summary>
5402+
/// <param name="resolutionX">The new X resolution.</param>
5403+
/// <param name="resolutionY">The new Y resolution.</param>
5404+
/// <param name="filter">The filter to use.</param>
5405+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
5406+
public void Resample(double resolutionX, double resolutionY, FilterType filter)
5407+
{
5408+
using var mutator = new Mutator(_nativeInstance);
5409+
mutator.Resample(resolutionX, resolutionY, filter);
5410+
}
5411+
53995412
/// <summary>
54005413
/// Resize image in terms of its pixel size.
54015414
/// </summary>
@@ -5407,6 +5420,18 @@ public void Resample(PointD density)
54075420
mutator.Resample(density);
54085421
}
54095422

5423+
/// <summary>
5424+
/// Resize image in terms of its pixel size.
5425+
/// </summary>
5426+
/// <param name="density">The density to use.</param>
5427+
/// <param name="filter">The filter to use.</param>
5428+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
5429+
public void Resample(PointD density, FilterType filter)
5430+
{
5431+
using var mutator = new Mutator(_nativeInstance);
5432+
mutator.Resample(density, filter);
5433+
}
5434+
54105435
/// <summary>
54115436
/// Resets the page property of this image.
54125437
/// </summary>
@@ -5429,6 +5454,22 @@ public void Resize(uint width, uint height)
54295454
mutator.Resize(width, height);
54305455
}
54315456

5457+
/// <summary>
5458+
/// Resize image to specified size.
5459+
/// <para />
5460+
/// Resize will fit the image into the requested size. It does NOT fill, the requested box size.
5461+
/// Use the <see cref="IMagickGeometry"/> overload for more control over the resulting size.
5462+
/// </summary>
5463+
/// <param name="width">The new width.</param>
5464+
/// <param name="height">The new height.</param>
5465+
/// <param name="filter">The filter to use.</param>
5466+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
5467+
public void Resize(uint width, uint height, FilterType filter)
5468+
{
5469+
using var mutator = new Mutator(_nativeInstance);
5470+
mutator.Resize(width, height, filter);
5471+
}
5472+
54325473
/// <summary>
54335474
/// Resize image to specified geometry.
54345475
/// </summary>
@@ -5440,6 +5481,18 @@ public void Resize(IMagickGeometry geometry)
54405481
mutator.Resize(geometry);
54415482
}
54425483

5484+
/// <summary>
5485+
/// Resize image to specified geometry.
5486+
/// </summary>
5487+
/// <param name="geometry">The geometry to use.</param>
5488+
/// <param name="filter">The filter to use.</param>
5489+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
5490+
public void Resize(IMagickGeometry geometry, FilterType filter)
5491+
{
5492+
using var mutator = new Mutator(_nativeInstance);
5493+
mutator.Resize(geometry, filter);
5494+
}
5495+
54435496
/// <summary>
54445497
/// Resize image to specified percentage.
54455498
/// </summary>
@@ -5451,6 +5504,18 @@ public void Resize(Percentage percentage)
54515504
mutator.Resize(percentage);
54525505
}
54535506

5507+
/// <summary>
5508+
/// Resize image to specified percentage.
5509+
/// </summary>
5510+
/// <param name="percentage">The percentage.</param>
5511+
/// <param name="filter">The filter to use.</param>
5512+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
5513+
public void Resize(Percentage percentage, FilterType filter)
5514+
{
5515+
using var mutator = new Mutator(_nativeInstance);
5516+
mutator.Resize(percentage, filter);
5517+
}
5518+
54545519
/// <summary>
54555520
/// Resize image to specified percentage.
54565521
/// </summary>
@@ -5463,6 +5528,19 @@ public void Resize(Percentage percentageWidth, Percentage percentageHeight)
54635528
mutator.Resize(percentageWidth, percentageHeight);
54645529
}
54655530

5531+
/// <summary>
5532+
/// Resize image to specified percentage.
5533+
/// </summary>
5534+
/// <param name="percentageWidth">The percentage of the width.</param>
5535+
/// <param name="percentageHeight">The percentage of the height.</param>
5536+
/// <param name="filter">The filter to use.</param>
5537+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
5538+
public void Resize(Percentage percentageWidth, Percentage percentageHeight, FilterType filter)
5539+
{
5540+
using var mutator = new Mutator(_nativeInstance);
5541+
mutator.Resize(percentageWidth, percentageHeight, filter);
5542+
}
5543+
54665544
/// <summary>
54675545
/// Roll image (rolls image vertically and horizontally).
54685546
/// </summary>

src/Magick.NET/Native/MagickImage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,10 +621,10 @@ private unsafe sealed partial class NativeMagickImage : NativeInstance, INativeM
621621
public partial void ResetProfileIterator();
622622

623623
[Throws]
624-
public partial IntPtr Resample(double resolutionX, double resolutionY);
624+
public partial IntPtr Resample(double resolutionX, double resolutionY, FilterType filter);
625625

626626
[Throws]
627-
public partial IntPtr Resize(string geometry);
627+
public partial IntPtr Resize(string geometry, FilterType filter);
628628

629629
[Throws]
630630
public partial IntPtr Roll(nint x, nint y);

0 commit comments

Comments
 (0)