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 wkhtmltoimage-linux with all npm packages installed. Try it out:

var ToImage = require("wkhtmltoimage-linux") var URL = require("url"); exports.tonicEndpoint = function(request, response) { var query = URL.parse(request.url, true).query; var url = query.url; response.writeHead(200, {'Content-Type': 'image/png'}); ToImage.generate(url, { format: "png" }).pipe(response); }; var endpointURL = `https://tonicdev.io/${process.env.TONIC_ENDPOINT_PATH}`; // Visit the endpoint URL in your browser, or just submit the form below `<form target="img" action="${endpointURL}"> <input placeholder="enter a URL" name="url" /> <button type="submit">submit</button> <span>( ${endpointURL} )</span> </form> <iframe style="width:100%; height: 400px" name="img"></iframe>`

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

wkhtmltoimage-linux v0.1.5

A version of wkhtmltoimage package that vendors the linux binaries

node-wkhtmltoimage

A Node.js wrapper for the wkhtmltoimage command line tool. It converts HTML documents to images using WebKit. This was originally based on node-wkhtmltopdf and was written for thumbsrc.com.

Usage

var wkhtmltoimage = require('wkhtmltoimage');

// Optionally specify binary path
var wkhtmltoimage = require('wkhtmltoimage').setCommand(__dirname + '/bin/wkhtmltoimage');

// URL
wkhtmltoimage.generate('http://example.com/', { pageSize: 'letter' })
  .pipe(fs.createWriteStream('out.jpg'));
  
// HTML
wkhtmltoimage.generate('<h1>Hello world</h1>')
  .pipe(res);
  
// output to a file directly
wkhtmltoimage.generate('http://example.com/', { output: 'out.jpg' });

// Optional callback
wkhtmltoimage.generate('http://example.com/', { pageSize: 'letter' }, function (code, signal) {
});
wkhtmltoimage.generate('http://example.com/', function (code, signal) {
});

wkhtmltoimage is just a function, which you call with either a URL or an inline HTML string, and it returns a stream that you can read from or pipe to wherever you like (e.g. a file, or an HTTP response).

There are many options available to wkhtmltoimage. All of the command line options are supported as documented on the page linked to above. The options are camelCased instead-of-dashed as in the command line tool.

There is also an output option that can be used to write the output directly to a filename, instead of returning a stream.

Installation

First, you need to install the wkhtmltoimage (included with wkhtmltopdf) command line tool on your system. The easiest way to do this is to download a prebuilt version for your system.

Then install the node module, use npm:

npm install wkhtmltoimage

Be sure wkhtmltoimage is in your PATH when you're done installing. Alternatively, use .setCommand(path) to specify the binary path.

License

MIT

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