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)
})();