@jimp/plugin-print
print an image.
Last updated 5 years ago by alisowski .
MIT · Original npm · Tarball · package.json
$ npm install @jimp/plugin-print 
SYNC missed versions from official npm registry.

@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.

:star: ttf2fnt

:star: Littera

:star: 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
import Jimp from 'jimp';

async function main() {
  const font = await Jimp.loadFont(Jimp.FONT_SANS_32_BLACK);
}

main();

print

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/or alignmentY)
  • @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
import Jimp from 'jimp';

async function main() {
  const font = await Jimp.loadFont(Jimp.FONT_SANS_32_BLACK);
  const image = await Jimp.read(1000, 1000, 0x0000ffff);

  image.print(font, 10, 10, 'Hello World!');
}

main();

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.

Jimp.HORIZONTAL_ALIGN_LEFT;
Jimp.HORIZONTAL_ALIGN_CENTER;
Jimp.HORIZONTAL_ALIGN_RIGHT;

Jimp.VERTICAL_ALIGN_TOP;
Jimp.VERTICAL_ALIGN_MIDDLE;
Jimp.VERTICAL_ALIGN_BOTTOM;

Default align modes for image.print are:

{
    alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT,
    alignmentY: Jimp.VERTICAL_ALIGN_TOP
}
const font = await Jimp.loadFont(pathOrURL);

// prints 'Hello world!' on an image, middle and center-aligned
image.print(
  font,
  x,
  y,
  {
    text: 'Hello world!',
    alignmentX: Jimp.HORIZONTAL_ALIGN_CENTER,
    alignmentY: Jimp.VERTICAL_ALIGN_MIDDLE
  },
  maxWidth,
  maxHeight
);

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.

const font = await Jimp.loadFont(Jimp.FONT_SANS_32_BLACK);

image.print(
  font,
  10,
  10,
  'Hello world that wraps!',
  50,
  (err, image, { x, y }) => {
    image.print(font, x, y + 20, 'More text on another line', 50);
  }
);

measureText

Measure how wide a piece of text will be.

import Jimp from 'jimp';

async function main() {
  const font = await Jimp.loadFont(Jimp.FONT_SANS_32_BLACK);
  const image = await Jimp.read(1000, 1000, 0x0000ffff);

  Jimp.measureText(font, 'Hello World!');
}

main();

measureTextHeight

Measure how tall a piece of text will be.

import Jimp from 'jimp';

async function main() {
  const font = await Jimp.loadFont(Jimp.FONT_SANS_32_BLACK);
  const image = await Jimp.read(1000, 1000, 0x0000ffff);

  Jimp.measureTextHeight(font, 'Hello World!', 100);
}

main();

Current Tags

  • 1.1.5--canary.d9590e7.0                                ...           canary (2 months ago)
  • 1.6.0                                ...           latest (2 months ago)

242 Versions

  • 1.6.0                                ...           2 months ago
  • 1.5.0                                ...           2 months ago
  • 1.4.0                                ...           2 months ago
  • 1.3.0                                ...           2 months ago
  • 1.2.0                                ...           2 months ago
  • 1.1.5                                ...           2 months ago
  • 1.1.5--canary.d9590e7.0                                ...           2 months ago
  • 1.1.4                                ...           2 months ago
  • 1.1.4--canary.3197852.0                                ...           2 months ago
  • 1.1.3                                ...           2 months ago
  • 1.1.3--canary.34e8f3b.0                                ...           2 months ago
  • 1.1.2                                ...           2 months ago
  • 1.1.1                                ...           2 months ago
  • 1.1.1--canary.8356674.0                                ...           2 months ago
  • 1.1.0                                ...           2 months ago
  • 1.0.5                                ...           2 months ago
  • 1.0.4                                ...           2 months ago
  • 1.0.3                                ...           2 months ago
  • 1.0.2                                ...           2 months ago
  • 1.0.2--canary.4e85de0.0                                ...           2 months ago
  • 0.22.12                                ...           9 months ago
  • 0.22.11                                ...           9 months ago
  • 0.22.11--canary.c55989b.0                                ...           9 months ago
  • 0.22.10                                ...           a year ago
  • 0.22.9                                ...           a year ago
  • 0.22.8                                ...           2 years ago
  • 0.22.7                                ...           2 years ago
  • 0.22.6                                ...           2 years ago
  • 0.22.6--canary.1198.9324a88b87a1fc38b528af47ca707d97593dddaa.0                                ...           2 years ago
  • 0.22.5                                ...           2 years ago
  • 0.22.4                                ...           2 years ago
  • 0.22.4--canary.1187.30d10f964404705d383d7163b7d3f85baa2201b7.0                                ...           2 years ago
  • 0.22.3                                ...           2 years ago
  • 0.22.3--canary.1184.ff6583af74ba85d9555c36db2844886e269feb16.0                                ...           2 years ago
  • 0.22.2                                ...           2 years ago
  • 0.22.1                                ...           2 years ago
  • 0.22.1--canary.1173.30a931db5f6552c59e4c99f41fdb9e2b9ccf8291.0                                ...           2 years ago
  • 0.22.1--canary.1169.6db477d088d28aea43b31d9ca8b0eaf74dc511d1.0                                ...           2 years ago
  • 0.22.0                                ...           2 years ago
  • 0.21.4--canary.1163.d07ed6254d130e2995d24101e93427ec091016e6.0                                ...           2 years ago
  • 0.21.4--canary.1163.7b9287fff1036ae67190d5ea3a8dec9926373a63.0                                ...           2 years ago
  • 0.21.4--canary.1163.6a6ae39e83bd731ccd25120a160a75b32273f9bd.0                                ...           2 years ago
  • 0.21.4--canary.1163.a26f5b300ee88c2fadb9909dd390cb4380b32a42.0                                ...           2 years ago
  • 0.21.3                                ...           2 years ago
  • 0.21.2                                ...           2 years ago
  • 0.21.2--canary.1156.1f8a92bfc1cbc6b5f3ad2490d0ec86710c81f635.0                                ...           2 years ago
  • 0.21.2--canary.1156.ba9fec9d0c9109924b4a5acab31bcaef8159a610.0                                ...           2 years ago
  • 0.21.2--canary.1156.8b2cc45.0                                ...           2 years ago
  • 0.21.1                                ...           2 years ago
  • 0.21.1--canary.1153.3cc6d7b.0                                ...           2 years ago
  • 0.21.0                                ...           2 years ago
  • 0.21.0--canary.1149.a81f653.0                                ...           2 years ago
  • 0.21.0--canary.1149.3239903.0                                ...           2 years ago
  • 0.20.2                                ...           2 years ago
  • 0.20.1                                ...           2 years ago
  • 0.20.0                                ...           2 years ago
  • 0.19.0                                ...           2 years ago
  • 0.17.9--canary.1144.3455afd.0                                ...           2 years ago
  • 0.17.9--canary.1143.90575e6.0                                ...           2 years ago
  • 0.17.9--canary.fc042e5.0                                ...           2 years ago
  • 0.18.0                                ...           2 years ago
  • 0.17.9--canary.1141.cd4d455.0                                ...           2 years ago
  • 0.17.10                                ...           2 years ago
  • 0.17.9--canary.1140.e3ff49d.0                                ...           2 years ago
  • 0.17.9--canary.1140.4042b43.0                                ...           2 years ago
  • 0.17.9--canary.1140.831bc3c.0                                ...           2 years ago
  • 0.17.9                                ...           2 years ago
  • 0.17.8                                ...           2 years ago
  • 0.17.8--canary.1137.476d7bd.0                                ...           2 years ago
  • 0.17.7                                ...           2 years ago
  • 0.17.6                                ...           2 years ago
  • 0.17.6--canary.1137.5e459dc.0                                ...           2 years ago
  • 0.17.6--canary.cd893f3.0                                ...           2 years ago
  • 0.17.6--canary.1cb89cf.0                                ...           2 years ago
  • 0.17.5                                ...           2 years ago
  • 0.17.4                                ...           2 years ago
  • 0.17.3                                ...           2 years ago
  • 0.17.3--canary.1136.7f5f5d8.0                                ...           2 years ago
  • 0.17.2                                ...           2 years ago
  • 0.18.0--canary.1135.911ed04.0                                ...           2 years ago
  • 0.17.1                                ...           2 years ago
  • 0.17.1--canary.1134.e007a48.0                                ...           2 years ago
  • 0.17.1--canary.e22c14a.0                                ...           2 years ago
  • 0.18.0--canary.1133.54bf269.0                                ...           2 years ago
  • 0.17.0                                ...           2 years ago
  • 0.17.0--canary.1131.af3cb94.0                                ...           2 years ago
  • 0.16.13                                ...           2 years ago
  • 0.16.12                                ...           2 years ago
  • 0.16.11                                ...           2 years ago
  • 0.16.10                                ...           2 years ago
  • 0.16.9                                ...           2 years ago
  • 0.16.8                                ...           2 years ago
  • 0.16.7                                ...           2 years ago
  • 0.16.6                                ...           2 years ago
  • 0.16.5                                ...           2 years ago
  • 0.16.4                                ...           2 years ago
  • 0.16.3                                ...           2 years ago
  • 0.16.3-canary.993.1592.0                                ...           2 years ago
  • 0.16.3-canary.1045.1590.0                                ...           2 years ago
  • 0.16.3-canary.1082.1591.0                                ...           2 years ago
  • 0.16.3-canary.1040.1589.0                                ...           2 years ago
  • 0.16.3-canary.999.1588.0                                ...           2 years ago
  • 0.16.3-canary.1085.1581.0                                ...           2 years ago
  • 0.16.3-canary.1014.1579.0                                ...           2 years ago
  • 0.16.3-canary.1125.1580.0                                ...           2 years ago
  • 0.16.3-canary.1113.1404.0                                ...           2 years ago
  • 0.16.3-canary.1109.1388.0                                ...           2 years ago
  • 0.16.3-canary.1108.1382.0                                ...           2 years ago
  • 0.16.3-canary.1100.1371.0                                ...           2 years ago
  • 0.16.2                                ...           2 years ago
  • 0.16.2-canary.1087.1357.0                                ...           2 years ago
  • 0.16.2-canary.1094.1345.0                                ...           2 years ago
  • 0.16.2-canary.1093.1332.0                                ...           2 years ago
  • 0.16.2-canary.1086.1311.0                                ...           2 years ago
  • 0.16.2-canary.1084.1305.0                                ...           2 years ago
  • 0.16.2-canary.1082.1294.0                                ...           3 years ago
  • 0.16.2-canary.1080.1288.0                                ...           3 years ago
  • 0.16.2-canary.1073.1276.0                                ...           3 years ago
  • 0.16.2-canary.1070.1265.0                                ...           3 years ago
  • 0.16.2-canary.1052.1235.0                                ...           3 years ago
  • 0.16.2-canary.1051.1228.0                                ...           3 years ago
  • 0.16.2-canary.1045.1221.0                                ...           3 years ago
  • 0.16.2-canary.1016.1185.0                                ...           3 years ago
  • 0.16.2-canary.1008.1164.0                                ...           4 years ago
  • 0.16.2-canary.984.1126.0                                ...           4 years ago
  • 0.16.2-canary.969.1115.0                                ...           4 years ago
  • 0.16.2-canary.964.1101.0                                ...           4 years ago
  • 0.16.2-canary.956.1095.0                                ...           4 years ago
  • 0.16.2-canary.947.1077.0                                ...           4 years ago
  • 0.16.2-canary.938.1059.0                                ...           4 years ago
  • 0.16.2-canary.934.1053.0                                ...           4 years ago
  • 0.16.2-canary.919.1052.0                                ...           4 years ago
  • 0.16.1                                ...           4 years ago
  • 0.16.0                                ...           4 years ago
  • 0.15.1-canary.924.1021.0                                ...           4 years ago
  • 0.15.0                                ...           4 years ago
  • 0.14.1-canary.919.1005.0                                ...           4 years ago
  • 0.14.1-canary.911.993.0                                ...           4 years ago
  • 0.14.0                                ...           4 years ago
  • 0.14.0-canary.904.976.0                                ...           4 years ago
  • 0.13.0-canary.899.964.0                                ...           4 years ago
  • 0.13.0                                ...           4 years ago
  • 0.12.2-canary.899.952.0                                ...           4 years ago
  • 0.12.1                                ...           4 years ago
  • 0.12.1-canary.892.924.0                                ...           4 years ago
  • 0.12.0                                ...           4 years ago
  • 0.11.1-canary.891.908.0                                ...           4 years ago
  • 0.11.0                                ...           4 years ago
  • 0.10.5-canary.882.886.0                                ...           5 years ago
  • 0.10.4-canary.882.884.0                                ...           5 years ago
  • 0.10.4-canary.882.885.0                                ...           5 years ago
  • 0.10.3                                ...           5 years ago
  • 0.10.2                                ...           5 years ago
  • 0.10.2-canary.875.842.0                                ...           5 years ago
  • 0.10.1                                ...           5 years ago
  • 0.10.1-canary.870.821.0                                ...           5 years ago
  • 0.10.0                                ...           5 years ago
  • 0.9.9-canary.868.799.0                                ...           5 years ago
  • 0.9.9-canary.867.792.0                                ...           5 years ago
  • 0.9.8                                ...           5 years ago
  • 0.9.8-canary.866.767.0                                ...           5 years ago
  • 0.9.7                                ...           5 years ago
  • 0.9.7-canary.854.725.0                                ...           5 years ago
  • 0.9.6                                ...           5 years ago
  • 0.9.6-canary.860.700.0                                ...           5 years ago
  • 0.9.6-canary.857.681.0                                ...           5 years ago
  • 0.9.6-canary.858.667.0                                ...           5 years ago
  • 0.9.5                                ...           5 years ago
  • 0.9.4                                ...           5 years ago
  • 0.9.4-canary.845.627.0                                ...           5 years ago
  • 0.9.4-canary.841.620.0                                ...           5 years ago
  • 0.9.4-canary.838.613.0                                ...           5 years ago
  • 0.9.4-canary.832.606.0                                ...           5 years ago
  • 0.9.3-canary.825.599.0                                ...           5 years ago
  • 0.9.3                                ...           5 years ago
  • 0.9.3-canary.825.584.0                                ...           5 years ago
  • 0.9.2-canary.815.538.0                                ...           5 years ago
  • 0.9.1                                ...           5 years ago
  • 0.9.0                                ...           5 years ago
  • 0.8.6-canary.815.502.0                                ...           5 years ago
  • 0.8.6-canary.818.495.0                                ...           5 years ago
  • 0.8.6-canary.815.488.0                                ...           5 years ago
  • 0.8.6-canary.810.481.0                                ...           5 years ago
  • 0.8.5                                ...           5 years ago
  • 0.8.1-canary.791.466.0                                ...           5 years ago
  • 0.8.1-canary.789.460.0                                ...           5 years ago
  • 0.8.5-canary.799.447.0                                ...           5 years ago
  • 0.8.5-canary.1.b147e81.0                                ...           5 years ago
  • 0.8.5-canary.b147e81.0                                ...           5 years ago
  • 0.8.5-canary.753c2c9.0                                ...           5 years ago
  • 0.8.5-canary.800.426.0                                ...           5 years ago
  • 0.8.4                                ...           5 years ago
  • 0.8.4-canary.798.377.0                                ...           5 years ago
  • 0.8.3                                ...           5 years ago
  • 0.8.2-canary.792.360.0                                ...           5 years ago
  • 0.8.2-canary.792.353.0                                ...           5 years ago
  • 0.8.2-canary.792.349.0                                ...           5 years ago
  • 0.8.2-canary.792.339.0                                ...           5 years ago
  • 0.8.2-canary.792.332.0                                ...           5 years ago
  • 0.8.2                                ...           5 years ago
  • 0.8.2-canary.794.308.0                                ...           5 years ago
  • 0.8.1-canary.789.301.0                                ...           5 years ago
  • 0.8.2-canary.792.290.0                                ...           5 years ago
  • 0.8.2-canary.792.283.0                                ...           5 years ago
  • 0.8.1-canary.791.276.0                                ...           5 years ago
  • 0.8.1                                ...           5 years ago
  • 0.8.1-canary.786.262.0                                ...           5 years ago
  • 0.8.1-canary.786.242.0                                ...           5 years ago
  • 0.8.1-canary.786.232.0                                ...           5 years ago
  • 0.8.1-canary.786.223.0                                ...           5 years ago
  • 0.8.1-canary.786.217.0                                ...           5 years ago
  • 0.8.1-canary.786.211.0                                ...           5 years ago
  • 0.8.0                                ...           5 years ago
  • 0.7.1-canary.770.193.0                                ...           5 years ago
  • 0.7.0                                ...           5 years ago
  • 0.6.8                                ...           5 years ago
  • 0.6.8-canary.783.163.0                                ...           5 years ago
  • 0.6.7-canary.783.157.0                                ...           5 years ago
  • 0.6.7                                ...           5 years ago
  • 0.6.6                                ...           5 years ago
  • 0.6.5                                ...           5 years ago
  • 0.6.5-canary.784.124.0                                ...           5 years ago
  • 0.6.5-canary.784.118.0                                ...           5 years ago
  • 0.6.5-canary.eeb6481.0                                ...           5 years ago
  • 0.6.5-canary.4564f3c.0                                ...           5 years ago
  • 0.6.4                                ...           6 years ago
  • 0.6.2                                ...           6 years ago
  • 0.6.1                                ...           6 years ago
  • 0.6.0                                ...           6 years ago
  • 0.5.4                                ...           6 years ago
  • 0.5.3                                ...           6 years ago
  • 0.5.2                                ...           6 years ago
  • 0.5.1                                ...           6 years ago
  • 0.5.0                                ...           6 years ago
  • 0.4.0                                ...           6 years ago
  • 0.3.9                                ...           6 years ago
  • 0.3.9-alpha.0                                ...           6 years ago
  • 0.3.8                                ...           6 years ago
  • 0.3.7                                ...           6 years ago
  • 0.3.6                                ...           6 years ago
  • 0.3.6-alpha.6                                ...           6 years ago
  • 0.3.6-alpha.5                                ...           6 years ago
Downloads
Total 109
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 10
Dependencies (4)
Dev Dependencies (3)
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE