I am looking for a way to depixelize an image that I pixelized with this code. I want to know if I can change the samplesize variable value with an event listener or something like that. Thanks for reading this and I hope that someone will help me !
let c = document.createElement("canvas")
let img1 = new Image()
img1.onload = function() {
document.getElementById("img1").remove()
w = img1.width
h = img1.height
c.width = w
c.height = h
ctx = c.getContext("2d")
ctx.drawImage(img1, 0, 0,)
let pixelarr = ctx.getImageData(0,0,w,h).data
let samplesize = 10
for(let y=0;y<h;y+=samplesize)
for(let x=0;x<w;x+=samplesize) {
let p = (x+(y*w))*4
ctx.fillStyle = "rgba(" + pixelarr[p] + "," + pixelarr[p+1] + "," + pixelarr[p+2] + "," + pixelarr[p+3] + ")"
ctx.fillRect(x,y,samplesize, samplesize)
}
let img2 = new Image()
img2.src = c.toDataURL("img/jpeg")
img2.width = 600
document.body.appendChild(img2)
}
img1.src = document.getElementById("img1").src