Write text on an existing PNG using Node.js

I am trying to create a simple dynamic icon (png) to insert into static pages to find out the status of my application.

I would like to use an existing PNG image and write text on it with Node.js.
I found many libraries, but they all use Imagemagick or Cairo as their native dependencies, I would like to avoid installing anything else on the server.

Then I found lwip, but I cannot figure out how to write text with an image with it. How can i do

+7
image-processing
source share
1 answer

You can use jimp . It has a printing method:

var Jimp = require("jimp"); var fileName = 'test.png'; var imageCaption = 'Image caption'; var loadedImage; Jimp.read(fileName) .then(function (image) { loadedImage = image; return Jimp.loadFont(Jimp.FONT_SANS_16_BLACK); }) .then(function (font) { loadedImage.print(font, 10, 10, imageCaption) .write(fileName); }) .catch(function (err) { console.error(err); }); 
+9
source share

All Articles