Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/magick-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1935,15 +1935,17 @@ export class MagickImage extends NativeInstance implements IMagickImage {
blur(channels: Channels): void;
blur(radius: number, sigma: number): void;
blur(radius: number, sigma: number, channels: Channels): void;
blur(radiusOrChannel?: number | Channels, sigmaOrUndefined?: number, channelsOrUndefined?: Channels): void {
blur(radiusOrChannels?: number | Channels, sigmaOrUndefined?: number, channelsOrUndefined?: Channels): void {
let radius = 0;
const sigma = this.valueOrDefault(sigmaOrUndefined, 1);
let channels = this.valueOrDefault(channelsOrUndefined, Channels.Undefined);

if (typeof radiusOrChannel === 'number')
radius = radiusOrChannel;
else if (radiusOrChannel !== undefined)
channels = radiusOrChannel;
if (radiusOrChannels !== undefined) {
if (sigmaOrUndefined === undefined)
channels = radiusOrChannels;
else
radius = radiusOrChannels;
}

this.useException(exception => {
const instance = ImageMagick._api._MagickImage_Blur(this._instance, radius, sigma, channels, exception.ptr);
Expand Down
13 changes: 13 additions & 0 deletions tests/magick-image/blur.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0.

import { Channels } from '@src/enums/channels';
import { ErrorMetric } from '@src/enums/error-metric';
import { TestImages } from '@test/test-images';

describe('MagickImage#blur', () => {
Expand All @@ -12,6 +13,18 @@ describe('MagickImage#blur', () => {
});
});

it('should not confuse channels for radius', () => {
TestImages.Builtin.logo.use(imageA => {
imageA.clone(imageB => {
imageA.blur(Channels.Blue);
imageB.blur(4, 1);

const difference = imageB.compare(imageA, ErrorMetric.RootMeanSquared);
expect(difference).not.toBe(0);
})
});
});

it('should only blur the specified channel', () => {
TestImages.Builtin.logo.use(image => {
image.blur(5, 5, Channels.Green);
Expand Down