vendredi 4 octobre 2019

How to create an image in Node js?

I am working on a program that generates a quote and then places the text on top of a JPEG image. I have found a npm package to generate a quote, however I can't figure out how I can get the text and place it on top of an image?

I have tried searching for a npm package but was not able to find any. I also thought about having a preloaded image in my directory and from there I can add the text on top of it, however I have no idea how to do that. The only thing I can find is a package that generates pixelated images

  const Quote = require('inspirational-quotes');
console.log(Quote.getRandomQuote());
console.log(Quote.getQuote());

var fs = require('fs');
var imgGen = require('js-image-generator');

// Generate one image
imgGen.generateImage(800, 600, 80, function(err, image) {
    fs.writeFileSync('dummy.jpg', image.data);
});

// Generate multiple images
for(var i=1;i<=10;i++){
    imgGen.generateImage(800, 600, 80, function(err, image) {
        console.log("Generating image #" +i);
        fs.writeFileSync('dummy-' + i + '.jpg', image.data);
    });
}




Aucun commentaire:

Enregistrer un commentaire