Skip to content

Commit 65e7899

Browse files
committed
Added chopHorizontal and chopVertical to MagickImage.
1 parent 2614496 commit 65e7899

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

src/magick-image.ts

+22
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,20 @@ export interface IMagickImage extends IDisposable {
685685
*/
686686
chop(geometry: MagickGeometry): void;
687687

688+
/**
689+
* Chop image (remove vertical or horizontal subregion of image).
690+
* @param x The X offset from origin.
691+
* @param width The width of the part to chop horizontally.
692+
*/
693+
chopHorizontal(x: number, width: number): void;
694+
695+
/**
696+
* Chop image (remove vertical or horizontal subregion of image).
697+
* @param y The Y offset from origin.
698+
* @param height The height of the part to chop vertically.
699+
*/
700+
chopVertical(y: number, height: number): void;
701+
688702
/**
689703
* A variant of adaptive histogram equalization in which the contrast amplification is limited,
690704
* so as to reduce this problem of noise amplification.
@@ -2691,6 +2705,14 @@ export class MagickImage extends NativeInstance implements IMagickImage {
26912705
});
26922706
}
26932707

2708+
chopHorizontal(x: number, width: number): void {
2709+
this.chop(new MagickGeometry(x, 0, width, 0));
2710+
}
2711+
2712+
chopVertical(y: number, height: number): void {
2713+
this.chop(new MagickGeometry(0, y, 0, height));
2714+
}
2715+
26942716
clahe(xTiles: number, yTiles: number, numberBins: number, clipLimit: number): void;
26952717
clahe(xTiles: Percentage, yTiles: Percentage, numberBins: number, clipLimit: number): void;
26962718
clahe(xTiles: number | Percentage, yTiles: number | Percentage, numberBins: number, clipLimit: number): void {
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
3+
Licensed under the Apache License, Version 2.0.
4+
*/
5+
6+
import { TestFiles } from '@test/test-files';
7+
8+
describe('MagickImage#chopHorizontal', () => {
9+
it('should remove part of the image', () => {
10+
TestFiles.Images.Builtin.logo.use(image => {
11+
image.chopHorizontal(100, 50);
12+
13+
expect(image.width).toBe(590);
14+
expect(image.height).toBe(480);
15+
16+
expect(image).toHavePixelWithColor(99, 94, '#fff');
17+
expect(image).toHavePixelWithColor(100, 94, '#f00');
18+
expect(image).toHavePixelWithColor(99, 130, '#f5ee36');
19+
expect(image).toHavePixelWithColor(100, 130, '#f00');
20+
});
21+
});
22+
});
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
3+
Licensed under the Apache License, Version 2.0.
4+
*/
5+
6+
import { TestFiles } from '@test/test-files';
7+
8+
describe('MagickImage#chopVertical', () => {
9+
it('should remove part of the image', () => {
10+
TestFiles.Images.Builtin.logo.use(image => {
11+
image.chopVertical(24, 42);
12+
13+
expect(image.width).toBe(640);
14+
expect(image.height).toBe(438);
15+
16+
expect(image).toHavePixelWithColor(301, 23, '#f5ee36');
17+
expect(image).toHavePixelWithColor(301, 24, '#f00');
18+
expect(image).toHavePixelWithColor(247, 23, '#fff');
19+
expect(image).toHavePixelWithColor(247, 24, '#f00');
20+
});
21+
});
22+
});

0 commit comments

Comments
 (0)