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

246
Views
How would I crop an image's transparent borders via javascript?

So, I have a stack of ~10 images layered on top of each other via a for loop. I need to be able to click them individually, but the images are all 1080x1350. The images are mainly transparent with a small area of non-transparency, so I'm wondering how I would crop them to only include the non-transparent pixels while retaining the same position. I'm extremely new to javascript, so keep that in mind when explaining stuff to me :)

Imagine this is the input image. The blue background are the transparent pixels, for example's sake. I would want to crop them to receive this output image while retaining the same position on the website, and keep on doing it until the for loop ends.

Here is what I currently have, it takes from a js file storing variables about the file paths of each image, and places them ontop of each other

$(function () {

for (const [index] of Object.entries(data)) {
    var filePath = data[index].file;

    $(".images").append(`<div class="${index}"></div>`)
    $(`.${index}`).append(`<img src="${filePath}" alt="">`)
}

js file:

const data = {
"001": {
    "file": "images2/Box.png",
},
"002": {
    "file": "images2/Floor.png",
},
"003": {
    "file": "images2/Person.png",
},
"004":{
    "file": "images2/Cube2.png"
},
"005":{
    "file": "images2/Top pillar.png"
},
"006":{
    "file": "images2/Trees.png"
}

};
about 4 years ago · Juan Pablo Isaza
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!