npm install cats-generator
-
getImage()
- Makes request to 'https://cataas.com/cat' and returnsPromise<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
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
- 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
-
- x: number
- y: number
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();