Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

grayscale image in canvas

window.onload = function() {
let canvas = document.getElementById("c");

	  let ctx = canvas.getContext("2d");
    canvas.width=50;
    canvas.height=50;

		let srcImg = document.getElementById("sof");
		ctx.drawImage(srcImg, 0, 0, ctx.canvas.width, ctx.canvas.height);
		let imgData = ctx.getImageData(0, 0, ctx.canvas.width, ctx.canvas.height);
		let pixels = imgData.data;
		for (var i = 0; i < pixels.length; i += 4) {
		  
		let lightness = parseInt((pixels[i] + pixels[i + 1] + pixels[i + 2])/3);
    
		  pixels[i] = lightness; 
		  pixels[i + 1] = lightness; 
		  pixels[i + 2] = lightness; 
		}
		ctx.putImageData(imgData, 0, 0);
	  }
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to make a string with unique characters js 
Javascript :: sequelize operators 
Javascript :: aes 256 nodejs 
Javascript :: axios httponly cookie 
Javascript :: Multiple children were passed to <Link with `href` of `/escritorio/opcion1` but only one child is supported 
Javascript :: mongodb unwind 
Javascript :: insert element in specific index javascript 
Javascript :: how to convert seconds in hours minutes and seconds js 
Javascript :: hammer js 
Javascript :: come andare a capo su javascript 
Javascript :: Print array of objects js 
Javascript :: github actions ssh 
Javascript :: how to check if text input has spaces javascript 
Javascript :: what is jquery 
Javascript :: javascript combine two index elements 
Javascript :: jquery not readonly 
Javascript :: process.env 
Javascript :: webpack setup proxy manual 
Javascript :: check if number is float 
Javascript :: create loop to specific length react 
Javascript :: discord.js embed timestamp 
Javascript :: json search javascript 
Javascript :: jquery detect shift tab 
Javascript :: discord.js start 
Javascript :: import js file 
Javascript :: Environment key "jest/globals" is unknown 
Javascript :: firebase admin delete user 
Javascript :: express url redirect 
Javascript :: jquery loop 0 to 10 
Javascript :: angular socket.io with token header 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =