O
O
olezhenka2018-03-14 21:03:54
JavaScript
olezhenka, 2018-03-14 21:03:54

How to paste text on an image with a background in the middle and multiline?

I just need to sculpt text on images where there should be a black background. I decided to paste the text on the newly created object, get the size of the output result in pixels, add a background and merge it with the image itself. This is how shit turned out in the end:

gm(400, 100, 'black')
      .font("Helvetica.ttf", 50)
      .fill('#333')
      .drawText(0, 0, 'hello world how are you me interesting ???', 'Center')
      .write('new.jpg', (err) => {
        if (err) console.log(err);
        gm('new.jpg').size(function(err, size) {
          console.log('size: ', size);
                      // .drawRectangle(coords, size)
        });
      });

and the problem - I get the size given initially, which I do not need, I need a dependent size resulting from the size of the text.
Please help, mb there are other modules for this work

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question