Converts source code to high quality images.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
themes
.gitignore
.npmignore
LICENSE
README.md
example.png
index.js
package-lock.json
package.json

README.md

src2img

NPM version JavaScript Style Guide

Converts source code to high quality images.

Install

Install with npm:

$ npm i src2img --save

Usage

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)

src2img({
  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: names.map(name => [
    fs.readFileSync(path.join(src, name)).toString(),
    'javascript' // https://prismjs.com/index.html#languages-list
    // See https://www.npmjs.com/package/filename2prism for getting alias from filename
  ])
}).then(images => Promise.all(images.map(
  (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:

example

Related

Contributing

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

Running Tests

Install dev dependencies:

$ npm i -d && npm test

Author

Tomer Aberbach

License

Copyright © 2018 Tomer Aberbach Released under the MIT license.