最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

Jimp.measureTextHeight例外:errorTypeError:无法读取的未定义的属性“lineHeight是”

IT培训 admin 4浏览 0评论

Jimp.measureTextHeight例外:errorTypeError:无法读取的未定义的属性“lineHeight是”

    let Jimp = require('jimp');
    var sizeOf = require('image-size');
    var mergeImg =require('merge-img');
    var dimensions = sizeOf('image/wall.png');
    console.log(dimensions.width, dimensions.height);        
    let image = new Jimp(dimensions.width, dimensions.height, 'green', (err,       image) => {
      if (err) throw err
    })        
    let message = 'Here the text is being added in the bottom center of the image.'
    let x = 10
    let y = 10  

    try{
    var textHeight=  Jimp.measureTextHeight(Jimp.FONT_SANS_32_BLACK, 'Some string', 100);        
    console.log("text height -"+textHeight);     
    }catch(ex)
    {
     console.log("error" + ex)
    }
    Jimp.loadFont(Jimp.FONT_SANS_16_BLACK)
      .then(font => {            
        image.print(font, x, y, message,dimensions.width)
        return image
      }).then(image => {
        let file = `new_name.${image.getExtension()}`
        return image.write("processed-image/out.png",function(err,    file){console.log(err)}) // save
      })

功能服从跳投掷measureTextHeight例外。我测量的宽度的基础上文字高度,创建一个图像,并写在上面的文字。

回答如下:
First argument you are passing wrong. Please see updated code.

const Jimp = require('jimp');
const sizeOf = require('image-size');
const dimensions = sizeOf('public/images/wall.jpeg');
const message = 'Here the text is being added in the bottom center of the image.'
const x = 10
const y = 10

new Jimp(dimensions.width, dimensions.height, 'green', (error, image) => {
    if (error) throw error;
    Jimp.loadFont(Jimp.FONT_SANS_16_BLACK)
      .then(font => {
        image.print(font, x, y, message, dimensions.width)
        const measureTextHeight = Jimp.measureTextHeight(font, 'Some string', 100);
        console.log('measureTextHeight =>', measureTextHeight);
        return image
      }).then(image => image.write("public/images/out.png", (error, file) => {
        if (error) throw error;
        return file;
      }))
  });

Jimp.measureTextHeight例外:errorTypeError:无法读取的未定义的属性“lineHeight是”

    let Jimp = require('jimp');
    var sizeOf = require('image-size');
    var mergeImg =require('merge-img');
    var dimensions = sizeOf('image/wall.png');
    console.log(dimensions.width, dimensions.height);        
    let image = new Jimp(dimensions.width, dimensions.height, 'green', (err,       image) => {
      if (err) throw err
    })        
    let message = 'Here the text is being added in the bottom center of the image.'
    let x = 10
    let y = 10  

    try{
    var textHeight=  Jimp.measureTextHeight(Jimp.FONT_SANS_32_BLACK, 'Some string', 100);        
    console.log("text height -"+textHeight);     
    }catch(ex)
    {
     console.log("error" + ex)
    }
    Jimp.loadFont(Jimp.FONT_SANS_16_BLACK)
      .then(font => {            
        image.print(font, x, y, message,dimensions.width)
        return image
      }).then(image => {
        let file = `new_name.${image.getExtension()}`
        return image.write("processed-image/out.png",function(err,    file){console.log(err)}) // save
      })

功能服从跳投掷measureTextHeight例外。我测量的宽度的基础上文字高度,创建一个图像,并写在上面的文字。

回答如下:
First argument you are passing wrong. Please see updated code.

const Jimp = require('jimp');
const sizeOf = require('image-size');
const dimensions = sizeOf('public/images/wall.jpeg');
const message = 'Here the text is being added in the bottom center of the image.'
const x = 10
const y = 10

new Jimp(dimensions.width, dimensions.height, 'green', (error, image) => {
    if (error) throw error;
    Jimp.loadFont(Jimp.FONT_SANS_16_BLACK)
      .then(font => {
        image.print(font, x, y, message, dimensions.width)
        const measureTextHeight = Jimp.measureTextHeight(font, 'Some string', 100);
        console.log('measureTextHeight =>', measureTextHeight);
        return image
      }).then(image => image.write("public/images/out.png", (error, file) => {
        if (error) throw error;
        return file;
      }))
  });
发布评论

评论列表 (0)

  1. 暂无评论