最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

创建一个图像,并写在它服从跳带(节点JS)文本

运维笔记admin8浏览0评论

创建一个图像,并写在它服从跳带(节点JS)文本

创建一个图像,并写在它服从跳带(节点JS)文本

我开始与节点和我写这个计划没有成功。我打算创建一个颜色尺寸的图像,图像中写入文本,然后保存到一个文件中。该程序会以外的所有文字。我究竟做错了什么?

let Jimp = require('jimp');

let image = new Jimp(300, 530, 'green', (err, image) => {
    if (err) throw err;
});

let message = 'Hello!';
let x = 10;
let y = 10;
let maxWidth = 300;

Jimp.loadFont(Jimp.FONT_SANS_8_BLACK)
    .then(font => {
        image.print(font, x, y, message);
    });

let file = 'new_name' + '.' + image.getExtension();
回答如下:

我觉得@ barro32可能是正确的。我添加了一些代码,写出来的形象,似乎工作:

let Jimp = require('jimp')

let image = new Jimp(300, 530, 'green', (err, image) => {
  if (err) throw err
})

let message = 'Hello!'
let x = 10
let y = 10

Jimp.loadFont(Jimp.FONT_SANS_64_BLACK)
  .then(font => {
    image.print(font, x, y, message)
    return image
  }).then(image => {
    let file = `new_name.${image.getExtension()}`
    return image.write(file) // save
  })

其结果是:

发布评论

评论列表(0)

  1. 暂无评论