Skip to content

Instantly share code, notes, and snippets.

@codeskyblue
Created February 19, 2019 04:32
Show Gist options
  • Save codeskyblue/d6ec253da48efdc1520fbd147bba9a69 to your computer and use it in GitHub Desktop.
Save codeskyblue/d6ec253da48efdc1520fbd147bba9a69 to your computer and use it in GitHub Desktop.
Convert html file into image using Google puppeteer
const puppeteer = require('puppeteer');
const resolve = require("path").resolve;
// node html2image.js -i input.html -o output.png
(async () => {
var program = require("commander");
program
.version("0.1.0")
.option("-i, --input <path>", "input html")
.option("-o, --output <path>", "output image file")
.parse(process.argv)
const htmlPath = resolve(program.input)
console.log(htmlPath)
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('file://' +resolve(program.input));
await page.screenshot({
path: program.output
});
await browser.close();
})();
{
"dependencies": {
"commander": "^2.19.0",
"puppeteer": "^1.12.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment