简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM