1.5.1 • Published 1 year ago

diplomas-generator v1.5.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Generate diplomas

tests

A versatile tool for generating diplomas and certificates from a list of names, with support for customizable designs and output formats like JPG and PDF.

Example of generated diploma.

Basic usage

import { generateTitles } from "diplomas-generator";

// Configuration object for generating titles.
const config = {
  inputNames: "src/data/names.txt", // or [ "name1", "name2", ...]
  inputTitlePath: "src/image/title.jpg", // Path to the title image file
};

generateTitles(config)
  .then(() => {
    console.log("Diplomas generated successfully!");
  })
  .catch((error) => {
    console.error("Error generating diplomas:", error);
  });

Important This package uses the package node-canvas to generate the diplomas, so in some cases you need to install the OS dependencies of this package to use it. See the OS specific instructions here

ParameterDescription
inputNames*Required* File path for the text file containing the names. Can be an array of strings.
fontSizeFont size for the name on the diplomas.
colorText color for the name on the diplomas, in hexadecimal format.
textAlignHorizontal alignment for the name on the diplomas. "center", "start", "end", "left", "right"
positionNameXX coordinate (in pixels) for the horizontal position of the name on the diplomas.
positionNameYY coordinate (in pixels) for the vertical position of the name on the diplomas.
imageQualityQuality of the base image of the title on the diplomas, as a value between 0 and 1.
fontPathFile path for the text font for the names on the diplomas.
inputTitlePathFile path for the base image file of the title on the diplomas.
exportImgBoolean to enable or disable the export of the diplomas as JPG files.
outputImgPathOutput path to save the generated diplomas as images.
exportPDFBoolean to enable or disable the export of the diplomas as PDF files.
outputPdfPathOutput path to save the generated diplomas as PDF files.
enableLoggingBoolean to enable or disable the logging of the process.

Considerations

  • exportImg is the most expensive operation in the process, so if you don't need the images, set it to false to speed up the process.

  • inputNames, inputTitlePath, outputImgPath, and outputPdfPath should be relative paths to the project root.

  • positionNameX and positionNameY are the coordinates (px) of the name in the diploma. By default, the name is centered in the diploma. Use these parameters to adjust the position of the name in the diploma.

  • Use textAlign to adjust the horizontal alignment of the name relative to the positionNameX.

File names.txt should contain a list of names separated by new line.

Maria Perez
Patrick Smith
Jane Doe

CommonJS usage

const { generateTitles } = require("diplomas-generator");
const config {
  ...
}
generateTitles(config).then().catch();

Advanced usage

import { generateTitles } from "diplomas-generator";

// Configuration object for generating titles.
const config = {
  inputNames: "src/data/names.txt", // or [ "name1", "name2", ...]
  fontPath: "src/fonts/itcedscr.ttf", // Path to the font file
  fontSize: 220, // Font size in pixels
  color: "#000000", // Text color in hexadecimal format
  textAlign: "center", // Text alignment
  positionNameX: 1625, // X-coordinate position for placing the name
  positionNameY: 950, // Y-coordinate position for placing the name
  imageQuality: 0.9, // Image quality (0.1 to 1)
  inputTitlePath: "src/image/title.jpg", // Path to the title image file
  exportImg: true, // Whether to export images (default: true)
  outputImgPath: "output/img",
  exportPDF: true, // Whether to export PDF (default: true)
  outputPdfPath: "output/titles.pdf",
  enableLogging: true, // Whether to enable logging (default: false)
};

generateTitles(config)
  .then(() => {
    console.log("Diplomas generated successfully!");
  })
  .catch((error) => {
    console.error("Error generating diplomas:", error);
  });
1.5.1

1 year ago

1.5.0

1 year ago

1.4.14

1 year ago

1.4.13

1 year ago

1.4.12

1 year ago

1.4.9

1 year ago

1.4.11

1 year ago

1.4.8

1 year ago

1.4.10

1 year ago

1.4.7

1 year ago

1.4.6

1 year ago

1.4.5

1 year ago

1.4.4

1 year ago

1.4.3

1 year ago

1.3.3

1 year ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.3.2

1 year ago

1.1.4

1 year ago

1.3.1

1 year ago

1.1.3

1 year ago

1.3.0

1 year ago

1.1.2

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.2

1 year ago

1.0.0

1 year ago