src2img NPM Module

Converts source code to high quality images.


Install with npm:

$ npm i src2img --save


const fs = require('fs')
const path = require('path')
const src2img = require('src2img')

const src = 'path/to/sources'
const out = 'path/to/out'

const names = fs.readdirSync(src)

  fontSize: 20, // Font size and unit control the size and quality of the image
  fontSizeUnit: 'pt',
  padding: 3,
  paddingUnit: 'vw', // Using 'px' does not scale with font size
  type: 'png', // png or jpeg
  src: => [
    fs.readFileSync(path.join(src, name)).toString(),
    'javascript' //
    // See for getting alias from filename
}).then(images => Promise.all(
  (image, i) => fs.writeFileSync(path.join(out, `${names[i].replace(/\.[^.]+$/g, '')}.png`), image))

Look at the CLI package if you’d like to use this from the command line.

Some rendered code:



Pull requests and stars on the GitHub repository are always welcome. For bugs and feature requests, please create an issue.

Running Tests

Install dev dependencies:

$ npm i -d && npm test


Copyright © 2018 Tomer Aberbach Released under the MIT license.