Skip to content

Instantly share code, notes, and snippets.

@joelgriffith
Created February 23, 2018 00:07
Show Gist options
  • Save joelgriffith/a9b2d72c0672fd3170bd9ba33cf17f37 to your computer and use it in GitHub Desktop.
Save joelgriffith/a9b2d72c0672fd3170bd9ba33cf17f37 to your computer and use it in GitHub Desktop.
Large Puppeteer Images
const puppeteer = require('puppeteer');
const merge = require('merge-img');
const pageUrl = ''; // REPLACE ME
const pageElement = '#svgcanvas'; // REPLACE ME
(async() => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(pageUrl);
const $ele = await page.$(pageElement);
const { width, height } = await $ele.boundingBox();
// Split into two and re-merge downstream
return Promise.all([
page.screenshot({
clip: {
x: 0,
y: 0,
height,
width: Math.floor(width / 2),
},
}),
page.screenshot({
clip: {
x: Math.floor(width / 2),
y: 0,
height,
width: Math.floor(width / 2),
},
})
])
.then(([left, right]) => merge([left, right]))
.then((final) => final.write('temp.png', () => browser.close()))
.catch((error) => {
console.error(error);
browser.close();
});
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment