├── .babelrc ├── .eslintignore ├── .eslintrc ├── .gitignore ├── .prettierignore ├── .prettierrc.json ├── .travis.yml ├── .yarnrc ├── CHANGELOG.md ├── LICENSE ├── README.md ├── commitlint.config.js ├── jest-setup.js ├── package.json ├── rollup.config.js ├── src ├── __tests__ │ ├── __image_snapshots__ │ │ ├── index-test-js-puppeteer-social-image-render-social-image-article-template-must-accept-expected-params-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-article-template-must-accept-subtitle-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-article-template-must-generate-as-a-preview-image-as-expected-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-basic-template-must-accept-background-param-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-basic-template-must-accept-color-param-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-basic-template-must-accept-font-family-param-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-basic-template-must-accept-font-size-param-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-basic-template-must-accept-font-weight-param-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-basic-template-must-accept-google-font-param-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-basic-template-must-accept-image-url-param-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-basic-template-must-accept-logo-and-watermark-param-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-basic-template-must-accept-logo-param-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-basic-template-must-accept-unsplash-id-param-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-basic-template-must-accept-watermark-param-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-basic-template-must-accept-watermark-text-param-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-basic-template-must-accept-watermark-url-param-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-basic-template-must-generate-as-a-preview-image-as-expected-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-basic-template-must-not-generate-as-a-preview-image-when-using-an-invalid-preview-size-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-basic-template-must-pass-all-params-to-custom-templates-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-fiftyfifty-template-must-accept-expected-params-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-fiftyfifty-template-must-accept-optional-params-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-fiftyfifty-template-must-accept-split-diagonal-param-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-fiftyfifty-template-must-accept-split-diagonal-reverse-param-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-fiftyfifty-template-must-generate-as-a-preview-image-as-expected-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-fiftyfifty-template-must-prefer-watermark-to-footer-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-must-accept-a-custom-browser-instance-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-must-generate-an-image-as-expected-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-must-generate-an-image-with-a-custom-size-1-snap.png │ │ ├── index-test-js-puppeteer-social-image-render-social-image-must-generate-an-image-with-a-custom-template-1-snap.png │ │ └── index-test-js-puppeteer-social-image-render-social-image-must-generate-an-image-with-a-custom-template-when-providing-multiple-custom-templates-1-snap.png │ └── index.test.js ├── helpers │ ├── build-unsplash-url.js │ ├── compile-image-template.js │ ├── compile-preview.js │ ├── compile-template.js │ ├── index.js │ ├── resolve-base-params.js │ └── resolve-params.js ├── index.js └── templates │ ├── article.js │ ├── basic.js │ ├── fiftyfifty.js │ └── index.js └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/env"] 3 | } 4 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | node_modules 3 | 4 | # testing 5 | coverage 6 | 7 | # production artifacts 8 | build 9 | dist 10 | lib 11 | 12 | # non-lintable JS/JSON 13 | /packages/generator-*/app/templates 14 | /packages/generator-*/generators/app/templates 15 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": ["json"], 3 | "extends": ["eslint:recommended", "prettier"], 4 | "parser": "babel-eslint", 5 | "parserOptions": { 6 | "ecmaVersion": 6, 7 | "sourceType": "module", 8 | "ecmaFeatures": { 9 | "jsx": true, 10 | "generators": true, 11 | "experimentalObjectRestSpread": true 12 | } 13 | }, 14 | "env": { 15 | "browser": true, 16 | "commonjs": true, 17 | "es6": true, 18 | "node": true, 19 | "jest": true 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | 6 | # testing 7 | coverage 8 | 9 | # production 10 | build 11 | dist 12 | lib 13 | 14 | # misc 15 | .DS_Store 16 | *.log 17 | *.tgz 18 | .idea 19 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # `yarn` has its own opinions on `package.json`, so `prettier` should ignore it 2 | package.json 3 | 4 | 5 | # Non-committed directories 6 | node_modules 7 | coverage 8 | dist 9 | lib 10 | 11 | # Generated Markdown files 12 | CHANGELOG.md 13 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "semi": true 3 | } 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 10 4 | -------------------------------------------------------------------------------- /.yarnrc: -------------------------------------------------------------------------------- 1 | version-git-message "release: v%s" 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [0.8.1](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.8.0...v0.8.1) (2020-06-16) 2 | 3 | 4 | ### Bug Fixes 5 | 6 | * pass all params to custom templates ([327c4b3](https://github.com/chrisvxd/puppeteer-social-image/commit/327c4b3)) 7 | 8 | 9 | 10 | # [0.8.0](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.7.1...v0.8.0) (2020-06-05) 11 | 12 | 13 | ### Features 14 | 15 | * support custom image types without using a path ([bb621f7](https://github.com/chrisvxd/puppeteer-social-image/commit/bb621f7)) 16 | 17 | 18 | ### BREAKING CHANGES 19 | 20 | * the default type is now JPEG when not specifying the "output" param 21 | 22 | 23 | 24 | ## [0.7.1](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.7.0...v0.7.1) (2020-05-29) 25 | 26 | 27 | ### Bug Fixes 28 | 29 | * don't render broken previews for sizes that don't support it ([a8f3aa5](https://github.com/chrisvxd/puppeteer-social-image/commit/a8f3aa5)) 30 | 31 | 32 | 33 | # [0.7.0](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.6.0...v0.7.0) (2020-05-29) 34 | 35 | 36 | ### Features 37 | 38 | * add instagram sizes ([d2b5797](https://github.com/chrisvxd/puppeteer-social-image/commit/d2b5797)) 39 | * add pinterest size ([d3c652c](https://github.com/chrisvxd/puppeteer-social-image/commit/d3c652c)) 40 | * pass size param to custom templates ([400b1ec](https://github.com/chrisvxd/puppeteer-social-image/commit/400b1ec)) 41 | * support custom sizes ([787a49a](https://github.com/chrisvxd/puppeteer-social-image/commit/787a49a)) 42 | 43 | 44 | 45 | # [0.6.0](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.5.5...v0.6.0) (2020-02-03) 46 | 47 | 48 | ### Features 49 | 50 | * add logo and refined watermark to basic and article templates. Reduce font size. ([2539a79](https://github.com/chrisvxd/puppeteer-social-image/commit/2539a79)) 51 | 52 | 53 | 54 | ## [0.5.5](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.5.4...v0.5.5) (2020-01-30) 55 | 56 | 57 | ### Bug Fixes 58 | 59 | * ensure custom templates generate in all environments ([49d084a](https://github.com/chrisvxd/puppeteer-social-image/commit/49d084a)) 60 | 61 | 62 | 63 | ## [0.5.4](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.5.3...v0.5.4) (2020-01-30) 64 | 65 | 66 | ### Bug Fixes 67 | 68 | * fix invalid markup in article template, and add regression tests ([f7ef694](https://github.com/chrisvxd/puppeteer-social-image/commit/f7ef694)) 69 | 70 | 71 | 72 | ## [0.5.3](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.5.2...v0.5.3) (2020-01-30) 73 | 74 | 75 | ### Bug Fixes 76 | 77 | * fix invalid markup in all templates ([9ac863f](https://github.com/chrisvxd/puppeteer-social-image/commit/9ac863f)) 78 | * further fixes to image templates ([fe507f3](https://github.com/chrisvxd/puppeteer-social-image/commit/fe507f3)) 79 | * slight visual tweak to previews ([2096d6b](https://github.com/chrisvxd/puppeteer-social-image/commit/2096d6b)) 80 | 81 | 82 | 83 | ## [0.5.2](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.5.1...v0.5.2) (2020-01-30) 84 | 85 | 86 | ### Bug Fixes 87 | 88 | * don't nest
tags in preview, and render styles correctly ([749d5f3](https://github.com/chrisvxd/puppeteer-social-image/commit/749d5f3)) 89 | * tidy up borders in preview ([8e3bb6f](https://github.com/chrisvxd/puppeteer-social-image/commit/8e3bb6f)) 90 | 91 | 92 | ### Performance Improvements 93 | 94 | * slightly increase preview performance by avoiding calling setContent twice ([cb88485](https://github.com/chrisvxd/puppeteer-social-image/commit/cb88485)) 95 | 96 | 97 | 98 | ## [0.5.1](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.5.0...v0.5.1) (2020-01-30) 99 | 100 | 101 | ### Bug Fixes 102 | 103 | * ensure images and previews get cropped correctly ([1f894cf](https://github.com/chrisvxd/puppeteer-social-image/commit/1f894cf)) 104 | 105 | 106 | ### Performance Improvements 107 | 108 | * increase preview performance by 2x by only taking 1 screenshot ([72431de](https://github.com/chrisvxd/puppeteer-social-image/commit/72431de)) 109 | 110 | 111 | 112 | # [0.5.0](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.4.1...v0.5.0) (2020-01-30) 113 | 114 | 115 | ### Features 116 | 117 | * add support for generating previews wrapped in Twitter-style frame ([231c0db](https://github.com/chrisvxd/puppeteer-social-image/commit/231c0db)) 118 | 119 | 120 | 121 | ## [0.4.1](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.4.0...v0.4.1) (2020-01-27) 122 | 123 | 124 | ### Bug Fixes 125 | 126 | * ensure fiftyfifty takes watermark param ([a48ba54](https://github.com/chrisvxd/puppeteer-social-image/commit/a48ba54)) 127 | 128 | 129 | 130 | # [0.4.0](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.3.2...v0.4.0) (2020-01-27) 131 | 132 | 133 | ### Bug Fixes 134 | 135 | * ensure fiftyfifty handles image position correctly ([b99183a](https://github.com/chrisvxd/puppeteer-social-image/commit/b99183a)) 136 | * ensure googleFont param works for all templates, and add tests ([5805a46](https://github.com/chrisvxd/puppeteer-social-image/commit/5805a46)) 137 | * fix aspect ratio of unsplash images in fiftyfifty template ([107a139](https://github.com/chrisvxd/puppeteer-social-image/commit/107a139)) 138 | 139 | 140 | ### Features 141 | 142 | * add fiftyfifty template ([9958a33](https://github.com/chrisvxd/puppeteer-social-image/commit/9958a33)) 143 | * add support for googleFont parameter across all templates ([19332f0](https://github.com/chrisvxd/puppeteer-social-image/commit/19332f0)) 144 | * add support for logging output for debugging ([25f70a3](https://github.com/chrisvxd/puppeteer-social-image/commit/25f70a3)) 145 | 146 | 147 | 148 | ## [0.3.2](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.3.1...v0.3.2) (2020-01-22) 149 | 150 | 151 | ### Bug Fixes 152 | 153 | * ensure pages are always closed if using userBrowser ([d3bca06](https://github.com/chrisvxd/puppeteer-social-image/commit/d3bca06)) 154 | * ensure puppeteer is always set to headless ([c89653c](https://github.com/chrisvxd/puppeteer-social-image/commit/c89653c)) 155 | 156 | 157 | 158 | ## [0.3.1](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.3.0...v0.3.1) (2020-01-18) 159 | 160 | 161 | ### Bug Fixes 162 | 163 | * ensure more complex templates render ([9fea492](https://github.com/chrisvxd/puppeteer-social-image/commit/9fea492)) 164 | * use valid fallback font for image templates ([d1a9dc9](https://github.com/chrisvxd/puppeteer-social-image/commit/d1a9dc9)) 165 | 166 | 167 | 168 | # [0.3.0](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.2.1...v0.3.0) (2020-01-18) 169 | 170 | 171 | ### Bug Fixes 172 | 173 | * wait for fonts to load before rendering screenshots ([04502eb](https://github.com/chrisvxd/puppeteer-social-image/commit/04502eb)) 174 | 175 | 176 | ### Features 177 | 178 | * add browser param to allow for external puppeteer configuration ([33cdfdc](https://github.com/chrisvxd/puppeteer-social-image/commit/33cdfdc)) 179 | 180 | 181 | ### Performance Improvements 182 | 183 | * don't include Lato webfont in custom templates ([9ac12ff](https://github.com/chrisvxd/puppeteer-social-image/commit/9ac12ff)) 184 | 185 | 186 | 187 | ## [0.2.1](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.2.0...v0.2.1) (2020-01-17) 188 | 189 | 190 | ### Bug Fixes 191 | 192 | * fix rollup import so we can compile ([d375f6a](https://github.com/chrisvxd/puppeteer-social-image/commit/d375f6a)) 193 | 194 | 195 | 196 | # [0.2.0](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.1.1...v0.2.0) (2020-01-17) 197 | 198 | 199 | ### Features 200 | 201 | * add article template ([76be6d3](https://github.com/chrisvxd/puppeteer-social-image/commit/76be6d3)) 202 | * add web API ([ff1143e](https://github.com/chrisvxd/puppeteer-social-image/commit/ff1143e)) 203 | * move .saasify to chrisvxd/og-impact ([6af4da5](https://github.com/chrisvxd/puppeteer-social-image/commit/6af4da5)) 204 | * revamp basic template - unsplash support, tighter line heights and watermarks ([a8010b2](https://github.com/chrisvxd/puppeteer-social-image/commit/a8010b2)) 205 | * support lambda, and make puppeteer a peer dependency ([d21ca5e](https://github.com/chrisvxd/puppeteer-social-image/commit/d21ca5e)) 206 | * switch templates to web font Lato, closest match to Avenir Next ([72e2c1a](https://github.com/chrisvxd/puppeteer-social-image/commit/72e2c1a)) 207 | 208 | 209 | ### BREAKING CHANGES 210 | 211 | * basic template now uses the Lato font instead of Avenir Next 212 | * make puppeteer a peer dependency 213 | 214 | 215 | 216 | ## [0.1.1](https://github.com/chrisvxd/puppeteer-social-image/compare/v0.1.0...v0.1.1) (2019-05-20) 217 | 218 | 219 | ### Bug Fixes 220 | 221 | * correct package description ([6271a0b](https://github.com/chrisvxd/puppeteer-social-image/commit/6271a0b)) 222 | 223 | 224 | 225 | # [0.1.0](https://github.com/chrisvxd/puppeteer-social-image/compare/270d144...v0.1.0) (2019-05-20) 226 | 227 | 228 | ### Bug Fixes 229 | 230 | * close puppeteer browser after execution ([d71c8e7](https://github.com/chrisvxd/puppeteer-social-image/commit/d71c8e7)) 231 | * ensure getImage runs ([8295f4d](https://github.com/chrisvxd/puppeteer-social-image/commit/8295f4d)) 232 | 233 | 234 | ### Features 235 | 236 | * actually write image to output ([6588b66](https://github.com/chrisvxd/puppeteer-social-image/commit/6588b66)) 237 | * add background param to basic template ([b070cfe](https://github.com/chrisvxd/puppeteer-social-image/commit/b070cfe)) 238 | * add image overlay and anchoring to basic template ([ac83f65](https://github.com/chrisvxd/puppeteer-social-image/commit/ac83f65)) 239 | * add initial getImage code ([270d144](https://github.com/chrisvxd/puppeteer-social-image/commit/270d144)) 240 | * add params to basic template ([bbcf58e](https://github.com/chrisvxd/puppeteer-social-image/commit/bbcf58e)) 241 | * add support for custom templates ([8bad772](https://github.com/chrisvxd/puppeteer-social-image/commit/8bad772)) 242 | * change getImage to default export ([13ef22c](https://github.com/chrisvxd/puppeteer-social-image/commit/13ef22c)) 243 | * return image buffer from render ([31193a4](https://github.com/chrisvxd/puppeteer-social-image/commit/31193a4)) 244 | * switch default image output to png ([3bf375e](https://github.com/chrisvxd/puppeteer-social-image/commit/3bf375e)) 245 | * tweaks to show off demo - it's working! ([d6f62c9](https://github.com/chrisvxd/puppeteer-social-image/commit/d6f62c9)) 246 | 247 | 248 | 249 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Chris Villa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # puppeteer-social-image 2 | 3 | [](https://travis-ci.com/chrisvxd/puppeteer-social-image) [](https://www.npmjs.com/package/puppeteer-social-image) [](https://prettier.io) 4 | 5 | Create dynamic social share images using HTML + CSS via puppeteer. For a hosted version, see [OGIMPACT](https://github.com/chrisvxd/og-impact). 6 | 7 |  8 | 9 | ## Installation 10 | 11 | ```sh 12 | npm i puppeteer-social-image --save 13 | ``` 14 | 15 | ## Usage 16 | 17 | ### Render "basic" template 18 | 19 | ```js 20 | import renderSocialImage from "puppeteer-social-image"; 21 | 22 | renderSocialImage({ 23 | template: "basic", 24 | templateParams: { 25 | imageUrl: 26 | "https://images.unsplash.com/photo-1557958114-3d2440207108?w=1950&q=80", 27 | title: "Hello, world" 28 | }, 29 | output: "image.png", 30 | size: "facebook" 31 | }); 32 | ``` 33 | 34 | ### Render custom template 35 | 36 | ```js 37 | import renderSocialImage from "puppeteer-social-image"; 38 | 39 | renderSocialImage({ 40 | templateBody: 'Name: {{ name }}
183 |googleFont: {{googleFont}}
184 |fontFamily: {{fontFamily}}
185 |unsplashId: {{unsplashId}}
186 |unsplashKeywords: {{unsplashKeywords}}
187 |size: {{size.width}}x{{size.height}}
188 |