Esperaba que el compuesto tomara una matriz de la imagen del objeto para colocarla con la posición. pero lo que obtuve es solo una salida original. primero extraigo la imagen a 16x16 y luego guardo la información sobre la posición que usaré en el compuesto. luego baraja esa información json. luego, pase a compuesto. pero la salida que obtuve es original. Intento todo el valor de la mezcla. solo genera un color diferente. incluso, valor de superposición. Todavía no sé, cuál es el problema. ¿Es la ordenación automática compuesta por tecla superior?
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) })();