Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

canvas js filter greyscale

const img = document.querySelector('img');
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');

img.onload = function() {
  canvas.width = img.width;
  canvas.height = img.height;
  ctx.filter = 'grayscale(1)';
  ctx.drawImage(img, 0, 0, img.width, img.height);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #canvas #js #filter #greyscale
ADD COMMENT
Topic
Name
6+2 =