graphicbar.js 772 B

1234567891011121314151617181920212223242526272829303132333435
  1. const gm = require('gm')
  2. module.exports = {
  3. create(maxLength, value) {
  4. const path = require('path').join(__dirname, '/bar/')
  5. const bar = gm(path + 'dummy.png')
  6. .geometry('+0x16')
  7. .tile(maxLength)
  8. .transparent('white')
  9. if (value > 0) {
  10. bar.montage(path + 'bar-full-left.png')
  11. } else {
  12. bar.montage(path + 'bar-empty-left.png')
  13. }
  14. for (let i = 0; i < maxLength - 2; i++) {
  15. if (i <= value - 2) {
  16. bar.montage(path + 'bar-full-mid.png')
  17. } else {
  18. bar.montage(path + 'bar-empty-mid.png')
  19. }
  20. }
  21. if (maxLength <= value) {
  22. bar.montage(path + 'bar-full-right.png')
  23. } else {
  24. bar.montage(path + 'bar-empty-right.png')
  25. }
  26. return bar.stream('PNG')
  27. },
  28. }