0

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);
    });
}

1

2 Answers 2

1

You may want to take a look at ImageMagick (or GraphicMagick), which is a command line binary (written in C++) that can do all sorts of image manipulations including compositing and text overlays. ImageMagick itself is pretty much a "Swiss knife" of image processing and has been around for many years, with lots of client libraries and ports for pretty much any environment.

For the command line reference and how to overlay text: https://imagemagick.org/Usage/annotating/#wmark_text

There are quite a few capable npm modules that provide ImageMagick/GraphicMagick wrappers, here is just one of them: https://www.npmjs.com/package/gm - and there are many more available

Hope that helps and good luck!

Sign up to request clarification or add additional context in comments.

Comments

0

The JS library "HTML2CANVAS" does what you need: http://html2canvas.hertzen.com/features/

There is a quick tutorial on YouTube here: https://www.youtube.com/watch?v=dPezJKcItuc

I hope that helps :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.