UNPKG

dokkie

Version:

Create good looking documentation from your Readme

50 lines 2.39 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createImage = exports.defaultImageSettings = void 0; const canvas_1 = require("canvas"); exports.defaultImageSettings = { size: { width: 1200, height: 1200, }, text: "default", background: "#fff", textSettings: { fontSize: 70, fontWeight: "bold", fontFamily: "Menlo", align: "center", baseline: "middle", color: "#ff0000", }, }; exports.createImage = (imageSettings) => __awaiter(void 0, void 0, void 0, function* () { const settings = Object.assign(exports.defaultImageSettings, imageSettings); const canvas = canvas_1.createCanvas(settings.size.width, settings.size.height); const context = canvas.getContext("2d"); context.fillStyle = settings.background; context.fillRect(0, 0, settings.size.width, settings.size.height); context.font = `${settings.textSettings.fontWeight} ${settings.textSettings.fontSize}pt ${settings.textSettings.fontFamily}`; context.textAlign = settings.textSettings.align; context.textBaseline = settings.textSettings.baseline; context.fillStyle = settings.textSettings.color; const text = "Hello, World!"; const textSettings = { width: context.measureText(text).width, height: 70, }; context.fillRect(settings.size.width / 2 - textSettings.width / 2, settings.size.height / 2 - textSettings.height / 2, textSettings.width + 20, 120); context.fillStyle = "#fff"; context.fillText(settings.text, settings.size.width / 2, settings.size.height / 2); return canvas.toBuffer("image/png"); }); //# sourceMappingURL=createImage.js.map