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;
}))
});