Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
Depixelize an image

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
about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!