Skip to content

Commit

Permalink
Add simple opengraph image generator
Browse files Browse the repository at this point in the history
  • Loading branch information
floscher committed May 10, 2023
1 parent ddeef80 commit 7046bb1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions server/src/service/opengraph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Canvas, CanvasRenderingContext2D, createCanvas } from "canvas";

function generateShareImage(title: string, date: Date) {
const canvas: Canvas = createCanvas(1280, 640);
const context: CanvasRenderingContext2D = canvas.getContext("2d", { alpha: false, pixelFormat: "RGB24" });

context.fillStyle = "#ff0000";
context.fillRect(20, 20, 600, 600);
context.font = "bold 48px sans-serif";
context.fillText(title, 660, 120, 600);
context.font = "bold 24px sans-serif";
context.fillText(date.toLocaleDateString("de-DE"), 660, 180, 600);

console.log(canvas.toDataURL("image/png"));
}

0 comments on commit 7046bb1

Please sign in to comment.