(
width: number,
height: number,
font: string,
{
x = 0,
y = 0,
text,
maxWidth,
maxHeight,
}: {
text:
| string
| {
text: string;
alignmentX?: HorizontalAlign;
alignmentY?: VerticalAlign;
};
maxWidth?: number;
maxHeight?: number;
x?: number;
y?: number;
},
)
| 11 | const Jimp = createJimp({ plugins: [methods], formats: [png, jpeg] }); |
| 12 | |
| 13 | async function createTextImage( |
| 14 | width: number, |
| 15 | height: number, |
| 16 | font: string, |
| 17 | { |
| 18 | x = 0, |
| 19 | y = 0, |
| 20 | text, |
| 21 | maxWidth, |
| 22 | maxHeight, |
| 23 | }: { |
| 24 | text: |
| 25 | | string |
| 26 | | { |
| 27 | text: string; |
| 28 | alignmentX?: HorizontalAlign; |
| 29 | alignmentY?: VerticalAlign; |
| 30 | }; |
| 31 | maxWidth?: number; |
| 32 | maxHeight?: number; |
| 33 | x?: number; |
| 34 | y?: number; |
| 35 | }, |
| 36 | ) { |
| 37 | const loadedFont = await loadFont(font); |
| 38 | const image = new Jimp({ width, height, color: 0xffffffff }); |
| 39 | |
| 40 | return image |
| 41 | .print({ font: loadedFont, x, y, text, maxWidth, maxHeight }) |
| 42 | .getBuffer("image/png"); |
| 43 | } |
| 44 | |
| 45 | describe("Write text over image", function () { |
| 46 | const fontDefs = { |
no test coverage detected
searching dependent graphs…