canvas.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import {spawn} from 'child_process';
  2. import {join} from 'path';
  3. const __dirname = global.__dirname(import.meta.url);
  4. /**
  5. * Levelup image
  6. * @param {String} teks
  7. * @param {Number} level
  8. * @return {Promise<Buffer>}
  9. */
  10. export function levelup(teks, level) {
  11. return new Promise(async (resolve, reject) => {
  12. if (!(global.support.convert || global.support.magick || global.support.gm)) return reject('Not Support!');
  13. const font = join(__dirname, '../src/font');
  14. const fontLevel = join(font, './level_c.otf');
  15. const fontTexts = join(font, './texts.otf');
  16. const xtsx = join(__dirname, '../src/lvlup_template.jpg');
  17. let anotations = '+1385+260'; // gapake else if kadang error
  18. if (level > 2) anotations = '+1370+260';
  19. if (level > 10) anotations = '+1330+260';
  20. if (level > 50) anotations = '+1310+260';
  21. if (level > 100) anotations = '+1260+260';
  22. const [_spawnprocess, ..._spawnargs] = [...(global.support.gm ? ['gm'] : global.support.magick ? ['magick'] : []),
  23. 'convert',
  24. xtsx,
  25. '-font',
  26. fontTexts,
  27. '-fill',
  28. '#0F3E6A',
  29. '-size',
  30. '1024x784',
  31. '-pointsize',
  32. '68',
  33. '-interline-spacing',
  34. '-7.5',
  35. '-annotate',
  36. '+153+200',
  37. teks,
  38. // original together
  39. '-font',
  40. fontLevel,
  41. '-fill',
  42. '#0A2A48',
  43. '-size',
  44. '1024x784',
  45. '-pointsize',
  46. '140',
  47. '-interline-spacing',
  48. '-1.2',
  49. '-annotate',
  50. anotations,
  51. level,
  52. '-append',
  53. 'jpg:-',
  54. ];
  55. const bufs = [];
  56. spawn(_spawnprocess, _spawnargs)
  57. .on('error', reject)
  58. .on('close', () => {
  59. return resolve(Buffer.concat(bufs));
  60. })
  61. .stdout.on('data', (chunk) => bufs.push(chunk));
  62. });
  63. }