Skip to content

Commit 5f8cd0d

Browse files
committed
Added chop to MagickImage.
1 parent 8f21159 commit 5f8cd0d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/magick-image.ts

+14
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,11 @@ export interface IMagickImage extends IDisposable {
680680
*/
681681
charcoal(radius: number, sigma: number): void;
682682

683+
/**
684+
* Chop image (remove vertical or horizontal subregion of image) using the specified geometry.
685+
*/
686+
chop(geometry: MagickGeometry): void;
687+
683688
/**
684689
* A variant of adaptive histogram equalization in which the contrast amplification is limited,
685690
* so as to reduce this problem of noise amplification.
@@ -2677,6 +2682,15 @@ export class MagickImage extends NativeInstance implements IMagickImage {
26772682
});
26782683
}
26792684

2685+
chop(geometry: MagickGeometry): void {
2686+
this.useException(exception => {
2687+
geometry._toRectangle(rectangle => {
2688+
const instance = ImageMagick._api._MagickImage_Chop(this._instance, rectangle, exception.ptr);
2689+
this._setInstance(instance, exception);
2690+
});
2691+
});
2692+
}
2693+
26802694
clahe(xTiles: number, yTiles: number, numberBins: number, clipLimit: number): void;
26812695
clahe(xTiles: Percentage, yTiles: Percentage, numberBins: number, clipLimit: number): void;
26822696
clahe(xTiles: number | Percentage, yTiles: number | Percentage, numberBins: number, clipLimit: number): void {

tests/magick-image/chop.spec.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
3+
Licensed under the Apache License, Version 2.0.
4+
*/
5+
6+
import { MagickGeometry } from '@src/types/magick-geometry';
7+
import { TestFiles } from '@test/test-files';
8+
9+
describe('MagickImage#chop', () => {
10+
it('should remove part of the image', () => {
11+
TestFiles.Images.Builtin.logo.use(image => {
12+
image.chop(new MagickGeometry(100, 100, 100, 100));
13+
14+
expect(image).toHavePixelWithColor(300, 99, '#fff');
15+
expect(image).toHavePixelWithColor(300, 100, '#f79868ff');
16+
expect(image).toHavePixelWithColor(406, 99, '#333636ff');
17+
expect(image).toHavePixelWithColor(406, 100, '#fff');
18+
});
19+
});
20+
});

0 commit comments

Comments
 (0)