Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

254
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda