cats-generator
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.2 • Public • Published

    cats-generator npm-image

    Simple promise-based npm library made to get cat images with custom text


    Install

    npm install cats-generator
    

    Docs

    Class — CatWithTextGenerator

    Class — CatImage

    • width - image width field.
    • height - image height field.
    • toBuffer() - Return cat image buffer.
    • addText(text, textOptions) - Adds text to image and returns Promise<CatImage>.
      • text - string
      • textOptions - TextOptions

    Enum — TextPosition

    • CENTER, CENTER_LEFT, CENTER_RIGHT, TOP_CENTER, TOP_LEFT, TOP_RIGHT, BOTTOM_CENTER, BOTTOM_LEFT, BOTTOM_RIGHT, CUSTOM
      • When you use CUSTOM you must use customPositionCoords in TextOptions.

    Interface — TextOptions

    • position: TextPosition
    • font: string
    • size: number
    • color?: string | CanvasGradient | CanvasPattern
      • Optional. Default: white
    • outlined?: boolean
      • Optional. Default: false
    • outlineColor?: string | CanvasGradient | CanvasPattern
      • Optional. Default: black
    • outlineSize: number
      • Optional. Default: 7
    • textPositionOffset: number,
      • Optional. Default: 10
    • customPositionCoords: TextStartPoint
      • Mandatory with TextPosition.CUSTOM

    Interface — TextStartPoint

    • x: number
    • y: number

    Example Usage

    const { CatWithTextGenerator, TextOptions, TextPosition } = require("cats-generator");
    const { writeFileSync } =  require("fs");
    
    async function main() {
        try {
            const catGenerator = new CatWithTextGenerator();
            const image = await catGenerator.getImage();
            const text = 'Hello World';
            const textOptions = {
                position: TextPosition.BOTTOM_CENTER,
                size: 64,
                font: 'Sans',
                outlined: true, 
                color: 'white',
            };
            const imageWithText = await image.addText(text, textOptions);
            const imageBuffer = imageWithText.toBuffer();
            writeFileSync('./file.png', imageBuffer);
            console.log('Image saved!');
        } catch(e) {
            console.error(e);
        }
    }
    
    main();

    Install

    npm i cats-generator

    DownloadsWeekly Downloads

    47

    Version

    1.1.2

    License

    ISC

    Unpacked Size

    49.1 kB

    Total Files

    7

    Last publish

    Collaborators

    • wnme