Skip to content

Commit

Permalink
Misc doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Sep 7, 2024
1 parent ae133c4 commit 1b94dee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
11 changes: 11 additions & 0 deletions packages/docs/src/content/docs/guides/migrate-to-v1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugin-blit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<I extends JimpClass>(image: I, options: BlitOptions) {
Expand Down
16 changes: 8 additions & 8 deletions plugins/plugin-print/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function xOffsetBasedOnAlignment<I extends JimpClass>(
font: BmFont<I>,
line: string,
maxWidth: number,
alignment: HorizontalAlign,
alignment: HorizontalAlign
) {
if (alignment === HorizontalAlign.LEFT) {
return 0;
Expand All @@ -57,7 +57,7 @@ function drawCharacter<I extends JimpClass>(
font: BmFont<I>,
x: number,
y: number,
char: BmCharacter,
char: BmCharacter
) {
if (char.width > 0 && char.height > 0) {
const characterPage = font.pages[char.page];
Expand All @@ -84,7 +84,7 @@ function printText<I extends JimpClass>(
x: number,
y: number,
text: string,
defaultCharWidth: number,
defaultCharWidth: number
) {
for (let i = 0; i < text.length; i++) {
const stringChar = text[i]!;
Expand Down Expand Up @@ -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<I extends JimpClass>(
Expand All @@ -141,7 +141,7 @@ export const methods = {
}: PrintOptions & {
/** the BMFont instance */
font: BmFont<I>;
},
}
) {
let {
// eslint-disable-next-line prefer-const
Expand Down Expand Up @@ -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") {
Expand All @@ -199,7 +199,7 @@ export const methods = {
font,
lineString,
maxWidth,
alignmentX,
alignmentX
);

printText(
Expand All @@ -208,7 +208,7 @@ export const methods = {
x + alignmentWidth,
y,
lineString,
defaultCharWidth,
defaultCharWidth
);
y += font.common.lineHeight;
});
Expand Down

0 comments on commit 1b94dee

Please sign in to comment.