// Repaint everything but the dark outline inside each cheek box with the body teal sampled beside it. const sharp = require("module").createRequire("/home/ubuntu/kalki-cli/projects/mybazaar-web/package.json")("sharp"); const [, , input, output, bodyAt, ...boxes] = process.argv; const [bx, by] = bodyAt.split(",").map(Number); (async () => { const { data, info } = await sharp(input).removeAlpha().raw().toBuffer({ resolveWithObject: true }); const { width } = info; const at = (x, y) => (y * width + x) * 3; const body = Array.from(data.subarray(at(bx, by), at(bx, by) + 3)); // Outline strokes are near-black green (g<80); everything lighter in a cheek box is blush or its rim. const isOutline = (i) => data[i + 1] < 80; let n = 0; for (const box of boxes) { const [x0, y0, x1, y1] = box.split(",").map(Number); for (let y = y0; y <= y1; y++) for (let x = x0; x <= x1; x++) { const i = at(x, y); if (!isOutline(i)) { data.set(body, i); n++; } } } await sharp(data, { raw: { ...info, channels: 3 } }).png().toFile(output); console.log(`repainted ${n} px with rgb(${body})`); })();