Skip to content

Instantly share code, notes, and snippets.

Last active April 30, 2021 06:24
  • Star 19 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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'})
Copy link

niladam commented Jan 4, 2019

Thank you for sharing this. I was looking on building something similar and i might be able to automate this somehow.

I'll get back to you if I do.

Justa sidenote for people reaching this without having read the article, the article's link is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment