Skip to content

Commit

Permalink
Add width/height/mime getters (#1327)
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie authored Sep 4, 2024
1 parent 91bb998 commit 931434a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ export function createJimp<
/** Formats that can be used with Jimp */
formats: Format<any>[] = [];

/** The original MIME type of the image */
mime?: string;

constructor(options: JimpConstructorOptions = emptyBitmap) {
// Add the formats
this.formats = formats;
Expand Down Expand Up @@ -327,6 +330,8 @@ export function createJimp<
await format.decode(actualBuffer)
) as InstanceType<typeof CustomJimp> & ExtraMethodMap;

image.mime = mime.mime;

attemptExifRotate(image, actualBuffer);

return image;
Expand Down Expand Up @@ -362,6 +367,16 @@ export function createJimp<
return "[object Jimp]";
}

/** Get the width of the image */
get width() {
return this.bitmap.width;
}

/** Get the height of the image */
get height() {
return this.bitmap.height;
}

/**
* Converts the Jimp instance to an image buffer
* @param mime The mime type to export to
Expand Down
15 changes: 15 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,14 @@ 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

## Importing

`Jimp` no longer uses a default export. Instead it uses named exports.

```js
import { Jimp } from "jimp";
```

## Positional Arguments to Options Objects

In jimp v0 there were many ways to provide arguments to a method.
Expand Down Expand Up @@ -140,3 +148,10 @@ const resized = await image

- `Jimp.AUTO` - This constant was only needed for positional arguments. It is no longer needed with the new API.
- `Jimp.MIME_*` - These are now part of the TS api when encoding

## Moved Functions

- `Jimp.intToRGBA` was moved `import { intToRGBA } from "jimp";`
- `image.getHeight()` was moved `image.height`
- `image.getWidth()` was moved `image.width`
- `image.getMIME()` was moved `image.mime`

0 comments on commit 931434a

Please sign in to comment.