Created
February 23, 2018 00:07
-
-
Save joelgriffith/a9b2d72c0672fd3170bd9ba33cf17f37 to your computer and use it in GitHub Desktop.
Large Puppeteer Images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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