api-opengraph-image
api-opengraph-image copied to clipboard
A service that returns an optimized OpenGraph Image from a domain name input.
trafficstars
Open Graph Image API
A runtime service to return optimized Open Graph images from a URL. Works with:
<meta name="og:image:secure_url"><meta name="og:image"><meta property="og:image"><meta name="twitter:image">
Usage
URLs have the formats:
/:url/
/:url/:size/
/:url/:size/:format/
/:url/:size/:format/onerror/
urlmust be URI encoded.size(optional) can besmall(375×),medium(650×), orauto(keep original width)formatmust by an output image format supported by Eleventy Image (autois supported)
/:url/onerror/
/:url/:size/onerror/
/:url/:size/:format/onerror/
- Appending the string value
onerrorto any valid URL format will return empty content (no default image) if an opengraph image is not found at the target URL. This will trigger<img onerror>in the browser which you can handle on the client (e.g.<img onerror="this.remove()">to remove the image).
Deploy your own
Demos
Advanced: Manual Cache Busting
If the images aren’t updating at a high enough frequency you can pass in your own cache busting key using an underscore prefix _ after your URL.
This can be any arbitrary string tied to your unique build, here’s an example that uses today’s date.
/:url/_20210802/
/:url/:size/_20210802/
/:url/:size/:format/_20210802/