Skip to content

Instantly share code, notes, and snippets.

@nbw
Created July 30, 2018 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbw/6dfcc071b4ef85d84802e1dfb022c4e7 to your computer and use it in GitHub Desktop.
Save nbw/6dfcc071b4ef85d84802e1dfb022c4e7 to your computer and use it in GitHub Desktop.
Pixelating a canvas image
function.pixelate(image, canvas, context, pixelSize) {
let wScaled, hScaled, scale;
scale = 1/pixelSize;
wScaled = canvas.width*scale;
hScaled = canvas.height*scale;
context.drawImage(image, 0, 0, wScaled, hScaled);
context.mozImageSmoothingEnabled = false;
context.imageSmoothingEnabled = false;
context.drawImage(canvas, 0, 0, wScaled, hScaled, 0, 0, canvas.width, canvas.height);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment