diff --git a/packages/docs/src/content/docs/guides/migrate-to-v1.mdx b/packages/docs/src/content/docs/guides/migrate-to-v1.mdx index 11ad4b0b..35d2c096 100644 --- a/packages/docs/src/content/docs/guides/migrate-to-v1.mdx +++ b/packages/docs/src/content/docs/guides/migrate-to-v1.mdx @@ -9,6 +9,17 @@ The goals of v1 were to: 2. Make jimp's API more consistent and easier to use 3. Many constants have been removed and are string value powered by TS +## Async/Sync + +In v0 of jimp there were a mix of async and sync methods for export. +In v1 all "export" methods are async. + +They have also been renamed: + +- `getBufferAsync` -> `getBuffer` +- `getBase64Async` -> `getBase64` +- `writeAsync` -> `write` + ## Importing `Jimp` no longer uses a default export. Instead it uses named exports. diff --git a/plugins/plugin-blit/src/index.ts b/plugins/plugin-blit/src/index.ts index f8cefe6d..7a18fbe9 100644 --- a/plugins/plugin-blit/src/index.ts +++ b/plugins/plugin-blit/src/index.ts @@ -37,7 +37,7 @@ export const methods = { * const image = await Jimp.read("test/image.png"); * const parrot = await Jimp.read("test/party-parrot.png"); * - * image.blit(parrot, x, y); + * image.blit({ src: parrot, x: 10, y: 10 }); * ``` */ blit(image: I, options: BlitOptions) { diff --git a/plugins/plugin-print/src/index.ts b/plugins/plugin-print/src/index.ts index 5aa0364a..f815a3c9 100644 --- a/plugins/plugin-print/src/index.ts +++ b/plugins/plugin-print/src/index.ts @@ -39,7 +39,7 @@ function xOffsetBasedOnAlignment( font: BmFont, line: string, maxWidth: number, - alignment: HorizontalAlign, + alignment: HorizontalAlign ) { if (alignment === HorizontalAlign.LEFT) { return 0; @@ -57,7 +57,7 @@ function drawCharacter( font: BmFont, x: number, y: number, - char: BmCharacter, + char: BmCharacter ) { if (char.width > 0 && char.height > 0) { const characterPage = font.pages[char.page]; @@ -84,7 +84,7 @@ function printText( x: number, y: number, text: string, - defaultCharWidth: number, + defaultCharWidth: number ) { for (let i = 0; i < text.length; i++) { const stringChar = text[i]!; @@ -130,7 +130,7 @@ export const methods = { * const image = await Jimp.read("test/image.png"); * const font = await Jimp.loadFont(Jimp.FONT_SANS_32_BLACK); * - * image.print(font, 10, 10, "Hello world!"); + * image.print({ font, x: 10, y: 10, text: "Hello world!" }); * ``` */ print( @@ -141,7 +141,7 @@ export const methods = { }: PrintOptions & { /** the BMFont instance */ font: BmFont; - }, + } ) { let { // eslint-disable-next-line prefer-const @@ -184,7 +184,7 @@ export const methods = { } const defaultCharWidth = Object.entries(font.chars).find( - (c) => c[1].xadvance, + (c) => c[1].xadvance )?.[1].xadvance; if (typeof defaultCharWidth !== "number") { @@ -199,7 +199,7 @@ export const methods = { font, lineString, maxWidth, - alignmentX, + alignmentX ); printText( @@ -208,7 +208,7 @@ export const methods = { x + alignmentWidth, y, lineString, - defaultCharWidth, + defaultCharWidth ); y += font.common.lineHeight; });