Path: blob/master/node_modules/@jimp/plugin-print/README.md
1126 views

@jimp/plugin-print
Print text on an image.
Jimp supports basic typography using BMFont format (.fnt) even ones in different languages! Just find a bitmap font that is suitable bitmap fonts.
Online tools are also available to convert TTF fonts to BMFont format. They can be used to create color font or sprite packs.
⭐ ttf2fnt
⭐ Littera
⭐ Hiero
Included Fonts
Jimp.FONT_SANS_8_BLACK
Jimp.FONT_SANS_10_BLACK
Jimp.FONT_SANS_12_BLACK
Jimp.FONT_SANS_14_BLACK
Jimp.FONT_SANS_16_BLACK
Jimp.FONT_SANS_32_BLACK
Jimp.FONT_SANS_64_BLACK
Jimp.FONT_SANS_128_BLACK
Jimp.FONT_SANS_8_WHITE
Jimp.FONT_SANS_16_WHITE
Jimp.FONT_SANS_32_WHITE
Jimp.FONT_SANS_64_WHITE
Jimp.FONT_SANS_128_WHITE
loadFont
Loads a bitmap font from a file
@param {string} file the file path of a .fnt file
@param {function(Error, Jimp)} cb (optional) a function to call when the font is loaded
@returns {Promise} a promise
Draws a text on a image on a given boundary
@param {Jimp} font a bitmap font loaded from
Jimp.loadFont
command@param {number} x the x position to start drawing the text
@param {number} y the y position to start drawing the text
@param {string} text the text to draw (string or object with
text
,alignmentX
, and/oralignmentY
)@param {number} maxWidth (optional) the boundary width to draw in
@param {number} maxHeight (optional) the boundary height to draw in - @param {function(Error, Jimp)} cb (optional) a function to call when the text is written
Alignment
Alignment modes are supported by replacing the str
argument with an object containing text
, alignmentX
and alignmentY
. alignmentX
defaults to Jimp.HORIZONTAL_ALIGN_LEFT
and alignmentY
defaults to Jimp.VERTICAL_ALIGN_TOP
.
You can align text using the following constants.
Default align modes for image.print
are:
Note: although maxWidth
and maxHeight
parameters are optional to print()
, they are needed to correctly align the text using the requested alignment mode.
Staggering Text
If you need to stagger text position along the x or y-axis the print method also returns the final coordinates as an argument to the callback.
measureText
Measure how wide a piece of text will be.
measureTextHeight
Measure how tall a piece of text will be.