Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

src2img

1.0.5 • Public • Published

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.

install

npm i src2img

Downloadsweekly downloads

0

version

1.0.5

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability