image-js
Version:
Image processing and manipulation in JavaScript
23 lines • 894 B
JavaScript
import { separableConvolution } from './convolution.js';
/**
* Blur an image. The pixel in the center becomes an average of the surrounding ones.
* @param image - Image to blur.
* @param options - Blur options.
* @returns The blurred image.
*/
export function blur(image, options) {
const { width, height } = options;
if (width < 1 || width % 2 === 0) {
throw new RangeError(`Invalid property "width". Must be an odd number greater than 0. Received ${width}.`);
}
if (height < 1 || height % 2 === 0) {
throw new RangeError(`Invalid property "height". Must be an odd number greater than 0. Received ${height}.`);
}
const kernelX = new Array(width).fill(1);
const kernelY = new Array(height).fill(1);
return separableConvolution(image, kernelX, kernelY, {
normalize: true,
...options,
});
}
//# sourceMappingURL=blur.js.map