![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
next-api-og-image
Advanced tools
Easy way to generate open-graph images dynamically using Next.js API Routes.
Simple library with purpose of providing easy way to dynamically
generate open-graph images using Next.js API routes.
npm i next-api-og-image -S
# or
yarn add next-api-og-image
import { withOGImage } from 'next-api-og-image'
export default withOGImage({ html: ({ myQueryParam }) => `<h1>${myQueryParam}</h1>` })
The Next.js API route where this code exists will open headless browser
on each request sent, put HTML content in the web page, screenshot it and return as binary data. The parameter of the function bound to html
in the configuration object is nothing else but request query parameters. This allows you to create HTML templates.
if you send GET HTTP request to api route with code presented above e.g. localhost:3000/api/foo?myQueryParam=hello
- it will render heading with content equal to 'hello'
Apart from html
configuration property (which is required), you can specify Content-Type and Cache-Control headers!
Example configuration with default values (apart from required html prop):
const nextApiOgImageConfig = {
/* Remember to specify `html` manually !!! */
contentType: 'image/png',
cacheControl: 'max-age 3600, must-revalidate',
}
Actually, next-api-og-image
exports utility function (fontFilesToBase64
) for doing that!
It can be done like this:
import { withOGImage, fontFilesToBase64 } from 'next-api-og-image'
export default withOGImage({
html: async ({ myQueryParam }) => {
const [interRegular] = await fontFilesToBase64(['Inter-Regular'], 'fonts')
return `
<style>
@font-face {
font-family: 'Inter';
font-style: normal;
font-weight: normal;
src: url(data:font/woff2;charset=utf-8;base64,${interRegular}) format('woff2');
}
body {
font-family: 'Inter', sans-serif;
}
</style>
<h1>${myQueryParam}</h1>`
},
})
see this example in Next.js project
You can find more examples here:
the example/
directory contains simple Next.js application implementing next-api-og-image
. To fully explore examples implemented in it by yourself - simply do npm link && cd examples && npm i && npm run dev
then navigate to http://localhost:3000/
This project is licensed under the MIT license.
All contributions are welcome.
FAQs
Easy way to generate open-graph images dynamically using Next.js API Routes.
The npm package next-api-og-image receives a total of 172 weekly downloads. As such, next-api-og-image popularity was classified as not popular.
We found that next-api-og-image demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.