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

377
Visualizações
sharp composite not work as expected, composite auto re-order?

i expected composite takes array of object image to place with position. but what i got is just original output. first i extract image to 16x16 then save information about position that will use in composite. then shuffle that information json. then, pass to composite. but the output i got is original. i try all blend value. it output different color only. even, overlay value. i still dont know, what the problem. is composite auto sort by top key?

const fs = require('fs');
const sharp = require('sharp');

function shuffle(array) {
    let currentIndex = array.length,  randomIndex;
  
    // While there remain elements to shuffle.
    while (currentIndex != 0) {
  
      // Pick a remaining element.
      randomIndex = Math.floor(Math.random() * currentIndex);
      currentIndex--;
  
      // And swap it with the current element.
      [array[currentIndex], array[randomIndex]] = [
        array[randomIndex], array[currentIndex]];
    }
  
    return array;
  }

(async () => {
    const image = await sharp('input.jpg');
    let metadata = await image.metadata();
    const wSizeBlock = 16;
    const hSizeBlock = 16;
    const wBlockLength = Math.floor(metadata.width / wSizeBlock);
    const hBlockLength = Math.floor(metadata.height / hSizeBlock);
    let total = 0;
    let taskDone = 0;
    let frame = [];

    const start_time = Date.now();
    console.log(start_time);

    for (let t=0; t < 1; t++) {
        for (let i=0; i < wBlockLength; i++) {
            for (let j=0; j < hBlockLength; j++) {
    
                image.extract({left: i*wSizeBlock, top: j*hSizeBlock, width: wSizeBlock, height: hSizeBlock})
                    .toFile(`output/crop${total}.jpg`);

                frame.push({
                    input: `output/crop${total}.jpg`,
                    left: i*wSizeBlock,
                    top: j*hSizeBlock
                });
    
                total += 1;
            }
        }
        total = 0;
        taskDone += 1;
        console.log(`Finish ${taskDone} task`)
    }

 frame = shuffle(frame)

sharp('input.jpg').composite(frame)
            .toFile(`test.jpg`)

const end_time = Date.now();
    console.log(end_time);
    const finish_time = end_time - start_time;
    console.log(finish_time)
    
})();
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