Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

376
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda