【发布时间】:2020-12-20 21:28:53
【问题描述】:
我正在尝试创建图像的轮廓。我已将背景设为黑色,但无法将所有其他颜色转换为灰色。
到目前为止我的代码:
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 这样的包,但它们似乎旨在替换一种颜色,而不是全部,而是一种。非常感谢任何帮助
【问题讨论】:
-
你有什么具体的错误吗?
-
你为什么同时使用
sharp和jimp? -
我无法查看您帖子中的链接,请直接将其嵌入问题中
-
@paroxyzm 没有任何错误,我只是不知道如何在这里实现我的目标
-
@Klaycon 完成。还添加了起始图像
标签: node.js typescript image image-processing silhouette