Skip to content

Commit 084d82f

Browse files
Add width/height/mime getters
1 parent 91bb998 commit 084d82f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

packages/core/src/index.ts

+15
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ export function createJimp<
155155
/** Formats that can be used with Jimp */
156156
formats: Format<any>[] = [];
157157

158+
/** The original MIME type of the image */
159+
mime?: string;
160+
158161
constructor(options: JimpConstructorOptions = emptyBitmap) {
159162
// Add the formats
160163
this.formats = formats;
@@ -327,6 +330,8 @@ export function createJimp<
327330
await format.decode(actualBuffer)
328331
) as InstanceType<typeof CustomJimp> & ExtraMethodMap;
329332

333+
image.mime = mime.mime;
334+
330335
attemptExifRotate(image, actualBuffer);
331336

332337
return image;
@@ -362,6 +367,16 @@ export function createJimp<
362367
return "[object Jimp]";
363368
}
364369

370+
/** Get the width of the image */
371+
get width() {
372+
return this.bitmap.width;
373+
}
374+
375+
/** Get the height of the image */
376+
get height() {
377+
return this.bitmap.height;
378+
}
379+
365380
/**
366381
* Converts the Jimp instance to an image buffer
367382
* @param mime The mime type to export to

packages/docs/src/content/docs/guides/migrate-to-v1.mdx

+15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ The goals of v1 were to:
99
2. Make jimp's API more consistent and easier to use
1010
3. Many constants have been removed and are string value powered by TS
1111

12+
## Importing
13+
14+
`Jimp` no longer uses a default export. Instead it uses named exports.
15+
16+
```js
17+
import { Jimp } from "jimp";
18+
```
19+
1220
## Positional Arguments to Options Objects
1321

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

141149
- `Jimp.AUTO` - This constant was only needed for positional arguments. It is no longer needed with the new API.
142150
- `Jimp.MIME_*` - These are now part of the TS api when encoding
151+
152+
## Moved Functions
153+
154+
- `Jimp.intToRGBA` was moved `import { intToRGBA } from "jimp";`
155+
- `image.getHeight()` was moved `image.height`
156+
- `image.getWidth()` was moved `image.width`
157+
- `image.getMIME()` was moved `image.mime`

0 commit comments

Comments
 (0)