Skip to content

Instantly share code, notes, and snippets.

@niladam
Forked from drewm/shoot-sharing-image.js
Created January 4, 2019 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niladam/67f9f06e9f4a44acb3842d40931d6385 to your computer and use it in GitHub Desktop.
Save niladam/67f9f06e9f4a44acb3842d40931d6385 to your computer and use it in GitHub Desktop.
Dynamic Social Sharing Images
const puppeteer = require('puppeteer');
const imagemin = require('imagemin');
const imageminPngquant = require('imagemin-pngquant');
// Get the URL and the slug segment from it
const url = process.argv[2];
const segments = url.split('/');
const slug = segments[segments.length-2];
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url + 'sharing');
await page.setViewport({
width: 600,
height: 315,
deviceScaleFactor: 2
});
await page.screenshot({path: slug + '.png'});
await browser.close();
await imagemin([slug + '.png'], 'build', {
plugins: [
imageminPngquant({quality: '75-90'})
]
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment