node.js - 使用 Jimp 将图像放在其他图像上

标签 node.js npm

我正在尝试在服务器端工作的 node.js 应用程序上编辑我的图像。此刻,我已经成功地在我的图像上添加了文字。我想在这张图片的左上角放置一个绿色矩形,我试过这个方法:

    Jimp.read(`borderTop.png`, function (err, top) {
        top.rotate(45);
        Jimp.read(`img.png`, function (err, image) {
            if (err) console.log(err);
            image.blit(top, 430, -250);
            Jimp.loadFont(`${__dirname}/../public/fonts/*.fnt`).then(function (font) {
                image.print(font, 315 - ((16 * 13 ) / 2), 0, "Hello, world!");
                image.write(finalName, (err) => {
                    return cb(null, `img.png`);
                });
            });
        });
    });


这是可行的,但它会删除边框下方的部分图像。

image for seeing

我试过了:

  • 仅使用.png 文件
  • 为我的图片添加不透明度
  • 仅使用具有 alpha channel 的图像

最佳答案

要让它工作,你必须使用:

image.composite( src, x, y );     // composites another Jimp image over this image at x, y 

来自 jimp doc

因为 image.blit() 只是删除图像下的所有内容。

关于node.js - 使用 Jimp 将图像放在其他图像上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49556025/

相关文章:

node.js - browser-perf 和 protractor-perf 和 perfjankie 之间的区别

javascript - 我可以向所有 WebSocket 客户端广播吗

node.js - 如何在 Windows 服务器上将 node.js 文件作为后台进程运行?

javascript - 通过 package-lock.json 减轻差异噪音

javascript - 如何在 webpack 上获取原始静态 html 文件

node.js - 找不到 Npm 模块 "grunt-sass"。安装了吗?

angularjs - Yeoman Bower 安装 vs npm 安装 vs grunt

node.js - 如何从 NodeJS 服务器下载 React 中的文件? (文件损坏)

javascript - 不使用模块从另一个网站抓取数据

node.js - 如何从单个 Node 项目发布多个 NPM 模块?