我正在尝试创建图像的轮廓。我已经将背景设置为黑色,但我无法将所有其他颜色转换为灰色。
到目前为止我的代码:
import sharp from "sharp";
import jimp from "jimp";
sharp("input.png")
.flatten()
.toFile("output.jpg")
.then(async (data) => {
const image = await jimp.read("output.jpg");
image.scan(0, 0, image.bitmap.width, image.bitmap.height, (x, y, idx) => {
if (image.bitmap.data[idx] >= 2) {
image.bitmap.data[idx] = 86;
image.bitmap.data[idx + 1] = 101;
image.bitmap.data[idx + 2] = 115;
image.bitmap.data[idx + 3] = image.bitmap.data[idx + 3];
}
});
image.write("output.jpg");
});
我看过像 replace-color 这样的包,但这些包似乎旨在替换一种颜色,而不是一种颜色。任何帮助深表感谢