Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript canvas grayscale

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: #javascript #canvas #grayscale
ADD COMMENT
Topic
Name
3+1 =