-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.d.ts
55 lines (39 loc) · 1.52 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
Get the dimensions of an image by reading the least amount of data.
Prefer this method.
@param stream - The image data.
@returns The image dimensions, or `undefined` if the image format is not supported or the image data is invalid.
@example
```
import {imageDimensionsFromStream} from 'image-dimensions';
// In this example, it will only read a few bytes of the image instead of fetching the whole thing.
const url = 'https://sindresorhus.com/unicorn';
const {body} = await fetch(url);
console.log(await imageDimensionsFromStream(body));
//=> {width: 1920, height: 1080}
```
@example
```
// Node.js example
import {createReadStream} from 'node:fs';
import {imageDimensionsFromStream} from 'image-dimensions';
const stream = ReadableStream.from(createReadStream('unicorn.png'));
console.log(await imageDimensionsFromStream(stream));
//=> {width: 1920, height: 1080}
```
*/
export function imageDimensionsFromStream(stream: ReadableStream<Uint8Array>): Promise<{width: number; height: number} | undefined>;
/**
Get the dimensions of an image.
Use this method if you already have the image loaded in memory.
@param data - The image data.
@returns The image dimensions, or `undefined` if the image format is not supported or the image data is invalid.
@example
```
import {imageDimensionsFromData} from 'image-dimensions';
const data = getImage();
console.log(imageDimensionsFromData(data));
//=> {width: 1920, height: 1080}
```
*/
export function imageDimensionsFromData(data: Uint8Array): {width: number; height: number} | undefined;