javascriptnode.jsgraphicsmagickgm

How to change font weight of text added on image using gm


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

Solution

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