Home / SEO and Site Tools / OG Image Maker

OG Image Maker in JavaScript, Free with Live Demo

Free Open Graph image maker in plain JavaScript. Pick a layout, type a title, choose colours or a photo background, and download a 1200 by 630 PNG ready for social sharing.

Open live demoDownload HTML fileView code on GitHub
OG Image Maker JavaScript project: a canvas tool that makes 1200 by 630 share images with your title and brand

Runs on: Canvas 2D and toBlob. Works in all modern browsers.

What is the OG Image Maker?

A small design tool for social share images. Choose one of three layouts, type a title, a small label and your site name, pick a colour and a background photo.

The title wraps and shrinks to fit, the preview updates instantly, and one click downloads a 1200 by 630 PNG you can use as your og:image.

Good for

  • Blog posts and articles
  • Product and landing pages
  • Event announcements
  • Any page that gets shared

What this project does

How it works

  1. Draw at full sizeThe canvas is 1200 by 630 pixels, the standard share size, and CSS only shrinks the preview. The download is always sharp.
  2. Wrap and shrink the titleWords are measured one by one to break lines. If the title needs more than four lines, the font gets smaller until it fits.
  3. Photos without taintingThe background photo loads with crossOrigin set to anonymous, so the canvas can still be exported as a PNG.

The key JavaScript

This is the heart of the project. The full file has the rest, including the screen layout and error handling.

function wrap(text, maxWidth, size) {
  ctx.font = `800 ${size}px sans-serif`;
  const lines = []; let line = "";
  for (const word of text.split(" ")) {
    const test = line ? line + " " + word : word;
    if (ctx.measureText(test).width > maxWidth && line) { lines.push(line); line = word; }
    else line = test;
  }
  lines.push(line);
  return lines.length > 4 ? wrap(text, maxWidth, size - 6) : lines;
}
canvas.toBlob((blob) => download(blob, "share-image.png"));

How to use it

  1. Click Download HTML file above.
  2. Open the file in a code editor, like VS Code.
  3. Run it from a local server with npx serve . so the camera, microphone and AI features are allowed.
  4. Change the text and colors, then upload it to GitHub Pages, Netlify or your own site. It is one file with no build step.

Questions people ask

Why 1200 by 630?

It is the size most social networks and chat apps use for large link previews.

Can I make these automatically for every post?

Yes. The same drawing code runs in a build script with a canvas library, or in a serverless function.

Why do some photos stop the download?

If a photo server does not allow cross origin use, the browser blocks export. Unsplash allows it.

More SEO and Site Tools projects