depict
v0.2.1
Published
Depict aims to easily render fallback images of web elements for platform that do not run code.
Readme
Depict
Depict aims to easily render fallback images of web elements for platform that do not run code.
Given a URL and optional CSS selector, depict outputs a screenshot of the rendered element.
With depict, charts based on living data can be rendered into flat images at regular intervals, no human interaction required. Think jobs numbers, congressional votes, etc.
Features
- Include an extra CSS file before rendering, useful for hiding UI components that don't make sense for static images
- Wait to take the screenshot until a selector exists with
--wait-for-selector(e.g. have your dynamic chart add a data attribute when it has rendered, and tell depict to wait for that)
Installation
Install globally:
npm install -g depictOr run with npx:
npx depictUsage
Usage: depict <URL> [options]
Options:
--version Show version number
-o, --output Output file (default: "screenshot.png")
-s, --selector CSS selector (default: "body")
--width Viewport width (default: 1440)
--height Viewport height (default: 900)
--delay Wait before screenshot in milliseconds (default: 1000)
--timeout Timeout in seconds for page load and selector waiting (default: 30)
--wait-for-selector Wait for CSS selector to exist before screenshot
--css CSS file(s) to inject (comma-separated)
--hide Hide element(s) before screenshot
--quality JPEG quality (0-100, only for .jpg/.jpeg output, default: 90)
--verbose Show detailed output
-h, --help Show helpExamples
For a specific chart:
depict \
http://www.nytimes.com/interactive/2013/07/07/business/a-nation-of-wineries.html \
-s '#g-chart-va' \
-o va-wine.pngTo render the full graphic:
depict \
http://www.nytimes.com/interactive/2013/07/07/business/a-nation-of-wineries.html \
-s '#main' \
-o a-nation-of-wineries.pngTo hide certain components, such as UI elements:
depict \
http://www.nytimes.com/interactive/2013/07/07/business/a-nation-of-wineries.html \
-s '.g-us-map-grid' \
--hide '.g-us-map-slider' \
-o us-wine.pngTo include a CSS file:
depict \
http://www.nytimes.com/interactive/2013/07/07/business/a-nation-of-wineries.html \
-s '.g-us-map-grid' \
--css exclude-ui.css \
-o us-wine.pngTo wait for dynamic content (e.g., chart renders after data loads):
depict \
https://www.washingtonpost.com/politics/interactive/2025/trump-administration-actions/ \
-s '.ribbon-chart' \
--wait-for-selector 'svg .chart' \
--timeout 60 \
-o chart.pngTo capture mobile viewport:
depict \
https://www.washingtonpost.com/politics/interactive/2025/trump-administration-actions/ \
-s '.ribbon-chart' \
--wait-for-selector 'svg .chart' \
--timeout 60 \
--width 375 \
-o chart.pngTo output JPEG format (smaller file size):
depict \
http://www.nytimes.com/interactive/2013/07/07/business/a-nation-of-wineries.html \
-s '#g-chart-va' \
-o chart.jpg \
--quality 85Pro tips
Run a local webserver to use depict during development:
python -m http.server 1337
depict http://localhost:1337 -s '#chart' -o chart.pngAdd a line in your Makefile to run depict automatically. (You are using make, right?)
fallback/chart.png: index.html
depict http://localhost:1337 -s '#chart' -o $@Hide multiple CSS selectors by using commas:
depict \
http://www.nytimes.com/interactive/2013/07/07/business/a-nation-of-wineries.html \
-s '.g-us-map-grid' \
--hide '.g-us-map-slider, .g-us-map-legend' \
-o us-wine.pngInclude multiple CSS files by using commas:
depict \
http://www.nytimes.com/interactive/2013/07/07/business/a-nation-of-wineries.html \
-s '.g-us-map-grid' \
--css 'exclude-ui.css, touch-device.css' \
-o us-wine.pngReleasing
To release a new version: ./scripts/release.sh patch (or minor/major)
