Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.
/ preview-imager Public archive

Preview Image Generator (in Golang with optional Node.js module)

Notifications You must be signed in to change notification settings

rensatsu/preview-imager

Repository files navigation

Preview Imager

Generate Image Previews for Open Graph tags.

Example

Image of an example

Usage

Install any ttf font (npm install --save @ibm/plex).

const { PreviewImager } = require("@rensatsu/preview-imager");
const path = require("path");

const fontPath = path.join(
    __dirname,
    "/node_modules/@ibm/plex/IBM-Plex-Sans/fonts/complete/ttf/"
);

(async () => {
    const pri = new PreviewImager("node-out.png", "test");
    pri.set("siteName", "Test Blog");
    pri.set("colorBg", "#665eba");
    pri.set("colorBgOverlay", "#665eba9f");
    pri.set("colorBgOverlay", "#0000009f");
    pri.set("paddingX", "50");
    pri.set("paddingY", "50");
    pri.set("lineSpacing", "1.75");
    pri.set("imagePath", path.join(__dirname, "/wallpaper.jpg"));
    pri.set("logoPath", path.join(__dirname, "/logo-32.png"));
    pri.set("logoX", "50");
    pri.set("logoY", "50");
    pri.set("paddingYSite", "25");
    pri.set("blurStrength", "5");
    pri.set("fontTitle", path.join(fontPath, "/IBMPlexSans-Bold.ttf"));
    pri.set("fontSiteName", path.join(fontPath, "/IBMPlexSans-Regular.ttf"));

    await pri.generate().catch(e => {
        console.error(e, e.output || null);
    });
})();