Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
@jimp/plugin-print
Advanced tools
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
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
Loads a bitmap font from a file
import Jimp from "jimp";
async function main() {
const font = await Jimp.loadFont(Jimp.FONT_SANS_32_BLACK);
}
main();
Draws a text on a image on a given boundary
Jimp.loadFont
commandtext
, alignmentX
, and/or alignmentY
)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 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.
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);
}
);
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();
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();
v0.22.5 (Tue Feb 21 2023)
:tada: This release contains work from new contributors! :tada:
Thanks for all your work!
:heart: Charly Poirier (@charlypoirier)
:heart: Ihor Bodnarchuk (@ihorbond)
@jimp/plugin-resize
FAQs
Unknown package
The npm package @jimp/plugin-print receives a total of 1,146,891 weekly downloads. As such, @jimp/plugin-print popularity was classified as popular.
We found that @jimp/plugin-print demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.