Turn audio into a shareable video. forked from nypublicradio/audiogram

initialize-canvas.js 938B

123456789101112131415161718192021222324252627282930313233343536373839
  1. var fs = require("fs"),
  2. path = require("path"),
  3. Canvas = require("canvas"),
  4. getRenderer = require("../renderer/"),
  5. serverSettings = require("../settings/");
  6. function initializeCanvas(options, cb) {
  7. // Fonts pre-registered in bin/worker
  8. var canvas = new Canvas(options.width, options.height),
  9. context = canvas.getContext("2d"),
  10. renderer = getRenderer(context).update(options);
  11. renderer.caption = options.caption;
  12. if (!options.backgroundImage) {
  13. return cb(null, renderer);
  14. }
  15. // Load background image from file (done separately so renderer code can work in browser too)
  16. fs.readFile(path.join(__dirname, "..", "settings", "backgrounds", options.backgroundImage), function(err, raw){
  17. if (err) {
  18. return cb(err);
  19. }
  20. var bg = new Canvas.Image;
  21. bg.src = raw;
  22. renderer.backgroundImage = bg;
  23. return cb(null, renderer);
  24. });
  25. }
  26. module.exports = initializeCanvas;