Skip to content

Commit

Permalink
Added liquidRescale to MagickImage.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Dec 25, 2021
1 parent e4bf984 commit f13d6d0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/magick-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export interface IMagickImage extends INativeInstance {
level(blackPoint: Percentage, whitePoint: Percentage, gamma: number): void;
level(channels: Channels, blackPoint: Percentage, whitePoint: Percentage): void;
level(channels: Channels, blackPoint: Percentage, whitePoint: Percentage, gamma: number): void;
liquidRescale(geometry: MagickGeometry): void;
liquidRescale(width: number, height: number): void;
modulate(brightness: Percentage): void;
modulate(brightness: Percentage, saturation: Percentage): void;
modulate(brightness: Percentage, saturation: Percentage, hue: Percentage): void;
Expand Down Expand Up @@ -637,6 +639,18 @@ export class MagickImage extends NativeInstance implements IMagickImage {
});
}

liquidRescale(geometry: MagickGeometry): void;
liquidRescale(width: number, height: number): void;
liquidRescale(widthOrGeometry: number | MagickGeometry, height?: number): void {
const geometry = typeof widthOrGeometry === 'number' ? new MagickGeometry(widthOrGeometry, height as number) : widthOrGeometry;
Exception.use(exception => {
_withString(geometry.toString(), geometryPtr => {
const instance = ImageMagick._api._MagickImage_LiquidRescale(this._instance, geometryPtr, geometry.x, geometry.y, exception.ptr);
this._setInstance(instance, exception);
});
});
}

modulate(brightness: Percentage): void;
modulate(brightness: Percentage, saturation: Percentage): void;
modulate(brightness: Percentage, saturation: Percentage, hue: Percentage): void;
Expand Down
47 changes: 47 additions & 0 deletions tests/magick-image/liquid-rescale.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
// Licensed under the Apache License, Version 2.0.

import { ImageMagick } from '../../src/image-magick';
import { IMagickImage, MagickImage } from '../../src/magick-image';
import { MagickGeometry } from '../../src/magick-geometry';
import '../custom-matcher';

let image: IMagickImage;

beforeEach(() => {
ImageMagick._api = (global as any).native;
image = MagickImage.create();
image.read('logo:');
});

afterEach(() => {
image.dispose();
});

describe('MagickImage#liquidRescale', () => {
it('should change the width of the image', () => {
image.liquidRescale(400, 0);
expect(image.width).toBe(400);
expect(image.height).toBe(300);
});

it('should change the height of the image', () => {
image.liquidRescale(0, 400);
expect(image.width).toBe(533);
expect(image.height).toBe(400);
});

it('with geometry should change the width of the image', () => {
image.liquidRescale(new MagickGeometry(300, 0));
expect(image.width).toBe(300);
expect(image.height).toBe(225);
});

it('with geometry should change the height of the image', () => {
image.liquidRescale(new MagickGeometry(0, 300));
expect(image.width).toBe(400);
expect(image.height).toBe(300);
expect(image).toHavePixelWithColor(250, 280, '#ed1f24ff');
expect(image).toHavePixelWithColor(174, 224, '#223e92ff');
});
});

0 comments on commit f13d6d0

Please sign in to comment.