cats-generator
v1.1.2
Published
Simple package that will help you to generate cat images with text
Downloads
10
Maintainers
Readme
cats-generator
Simple promise-based npm library made to get cat images with custom text
Install
npm install cats-generator
Docs
Class — CatWithTextGenerator
getImage()
- Makes request to 'https://cataas.com/cat' and returnsPromise<CatImage>
.
Class — CatImage
width
- image width field.height
- image height field.toBuffer()
- Return cat image buffer.addText(text, textOptions)
- Adds text to image and returnsPromise<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 usecustomPositionCoords
inTextOptions
.
- When you use
Interface — TextOptions
- position: TextPosition
- font: string
- size: number
- color?: string | CanvasGradient | CanvasPattern
- Optional. Default:
white
- Optional. Default:
- outlined?: boolean
- Optional. Default:
false
- Optional. Default:
- outlineColor?: string | CanvasGradient | CanvasPattern
- Optional. Default:
black
- Optional. Default:
- outlineSize: number
- Optional. Default:
7
- Optional. Default:
- textPositionOffset: number,
- Optional. Default:
10
- Optional. Default:
- customPositionCoords: TextStartPoint
Mandatory
withTextPosition.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();