-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added extractArea to the MagickReadSettings.
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. | ||
Licensed under the Apache License, Version 2.0. | ||
*/ | ||
|
||
import { ImageMagick } from '@src/image-magick'; | ||
import { MagickGeometry } from '@src/types/magick-geometry'; | ||
import { MagickReadSettings } from '@src/settings/magick-read-settings'; | ||
import { MagickColor } from '@src/magick-color'; | ||
|
||
describe('MagickReadSettings#extractArea', () => { | ||
it('should only read the specified area of the image', () => { | ||
const settings = new MagickReadSettings(); | ||
settings.extractArea = new MagickGeometry(350, 260, 100, 100); | ||
|
||
ImageMagick.read('logo:', settings, (image) => { | ||
expect(image.width).toBe(100); | ||
expect(image.height).toBe(100); | ||
|
||
expect(image).toHavePixelWithColor(0, 0, new MagickColor('#223e92ff')); | ||
}); | ||
}); | ||
|
||
it('should not outside the image', () => { | ||
const settings = new MagickReadSettings(); | ||
settings.extractArea = new MagickGeometry(600, 400, 100, 100); | ||
|
||
ImageMagick.read('logo:', settings, (image) => { | ||
expect(image.width).toBe(40); | ||
expect(image.height).toBe(80); | ||
|
||
expect(image).toHavePixelWithColor(0, 0, new MagickColor('#fff')); | ||
}); | ||
}); | ||
}); |