Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including code2image with all npm packages installed. Try it out:

var code2image = require("code2image")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

code2image v0.9.3

The library allows to create an image from a code with custom highlighting

code2image

NPM Version NPM Downloads

The library allows to render an image from a code snippet. It's based on node-canvas module.

Installation

$ npm install code2image

Example

var code2image = require('code2image');
var styles = { // it's default styles
    fontName: "monospace",
    fontMinSize: '6px',
    fontSize: '18px',
    fontRatio: 1,
    lineHeight: '20px',
    color: "black",
    background: "white",
    keyword: '#444 bold',
    built_in: "black",
    number: "black",
    string: "green",
    comment: "gray",
    decorator: "black",
    function: "black",
    class: "black",
    title: "black",
    params: "black",
    section: "black",
    regexp: "red",
    preprocessor: "black",
    attribute: "black",
};

code2image.render("var hello = 'hello';\nvar world = 'world';\nconsole.log(hello + ' ' + world);", 'test.png', styles, function(){
    console.log('ok!');
});

Result:

alt tag

Supported languages

https://github.com/kreshikhin/tolmach/blob/master/README.md#supported-languages

License

MIT

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free