1

I am using gm for adding text on the image. Now I want to make it bold, but I am not getting an option to change the font-weight. Any help is appreciated.

const gm = require('gm').subClass({imageMagick: true});
const imageUrl = 'image_url'
const text = 'Some_text';
const image = gm(`${imageUrl}`)
            .resize(518, 500)
            .fill('#f2f2f2')
            .font('Arial', 14) 
            .drawText(115, 470, `${text}`);
image.write(`result.png`, err => {
  if(err) return console.error(err);
  console.log('done');
});
Shrutika Patil
  • 565
  • 3
  • 18
  • Afaik, it doesn't do algorithmic font manipulation. If you need bold, you'll need to use a font that is bold by default such as "Arial Black" or "Arial-Bold", assuming you have either of those. – Ouroborus Oct 04 '20 at 10:55

1 Answers1

1

You can use gm.in() Custom Arguments like below

const gm = require('gm').subClass({imageMagick: true});
const imageUrl = 'image_url'
const text = 'Some_text';
const image = gm(`${imageUrl}`)
            .resize(518, 500)
            .fill('#f2f2f2')
            .font('Arial', 14) 
            .in('-weight', 'Bold')
            .drawText(115, 470, `${text}`);
image.write(`result.png`, err => {
  if(err) return console.error(err);
  console.log('done');
});