Skip to content

Download the image #10

Answered by neg4n
deadcoder0904 asked this question in Q&A
Oct 7, 2021 · 1 comments · 11 replies
Discussion options

You must be logged in to vote

You can try something like that:

In api route (pages/api/ogimage.js):

import { withOGImage } from "next-api-og-image";

export default withOGImage({
  template: { html: ({ test }) => `<h1>${test}</h1>` },
  dev: { inspectHtml: false },
});

then in regular Next.js page (pages/test.js):

import fetch from "isomorphic-unfetch";

export default function TestPage({ image }) {
  const src = `data:image/png;base64,${image}`;
  return (
    <div>
      <img src={src} />
    </div>
  );
}

export async function getStaticProps() {
  const response = await fetch(
    "http://localhost:3000/api/ogimage?test=populated%20at%20build%20time"
  );

  const arrayBuffer = await response.arrayBuffer();
  const 

Replies: 1 comment 11 replies

Comment options

You must be logged in to vote
11 replies
@deadcoder0904
Comment options

@neg4n
Comment options

@neg4n
Comment options

@deadcoder0904
Comment options

@neg4n
Comment options

Answer selected by neg4n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #9 on October 07, 2021 16:31.