Socket
Book a DemoInstallSign in
Socket

convolve

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

convolve

Canvas convolution filters

npmnpm
Version
0.0.2
Version published
Weekly downloads
168
242.86%
Maintainers
1
Weekly downloads
 
Created
Source

convolve

Canvas convolution filter.

API

convolve(input, result, width, height, matrix)

Apply convolution filter matrix to the given input, populating result.

convolve.canvas(canvas, matrix)

Apply the given convolution matrix to canvas and draw the results to its 2d context.

Example

var convolve = require('convolve');
var canvas = document.querySelector('canvas');
var ctx = canvas.getContext('2d');

var img = new Image;
img.onload = draw;
img.src = 'maru.jpg';

var sharpen = [
  [0, -3, 0],
  [-3, 21, -3],
  [0, -3, 0]
];

var blur = [
  [1, 1, 1],
  [1, 1, 1],
  [1, 1, 1]
];

var emboss = [
  [-18, -9, 0],
  [-9, 9, 9],
  [0, 9, 18]
];

var edges = [
  [0, 9, 0],
  [9, -36, 9],
  [0, 9, 0]
];

function draw() {
  canvas.width = img.width;
  canvas.height = img.height;
  ctx.drawImage(img, 0, 0);
  var data = ctx.getImageData(0, 0, img.width, img.height);
  var result = ctx.createImageData(img.width, img.height);
  convolve(data, result, img.width, img.height, edges);
  ctx.putImageData(result, 0, 0);
}

License

MIT

Keywords

canvas

FAQs

Package last updated on 26 Sep 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts