{"size": 678, "ext": "js", "max_stars_repo_path": "lib/services/image-service.js", "max_stars_repo_name": "ifahrentholz/node-image-generator", "max_stars_repo_stars_event_min_datetime": "2016-04-21T19:34:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-02T03:07:18.000Z", "max_issues_repo_path": "lib/services/image-service.js", "max_issues_repo_name": "ifahrentholz/node-image-generator", "max_issues_repo_issues_event_min_datetime": "2016-01-18T10:46:42.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T04:01:04.000Z", "max_forks_repo_path": "lib/services/image-service.js", "max_forks_repo_name": "ifahrentholz/node-image-generator", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 9, "max_issues_count": 52, "max_forks_count": null, "avg_line_length": 22.6, "max_line_length": 60, "alphanum_fraction": 0.5589970501}
var gm = require("gm");

module.exports = {

  /**
   * Create an image buffer or string
   * @param {Object} options
   * @param {Function} callback
   */
  createImage: function(options, callback) {
    var txt;
    if(!options.txt) {
      txt = options.width + "x" + options.height;
    } else {
      txt = options.txt;
    }

    gm(options.width, options.height, "#" + options.bg)
      .fill("#" + options.txtclr)
      .font(options.fontFamily, options.txtsize)
      .drawText(0, 0, txt, "center")
      .toBuffer(options.contentType, function(err, buffer) {
        if (err) {
          callback(err, null);
        }
        callback(null, buffer);
      });
  }
};
