1 | interface Size {
|
2 | width: number
|
3 | height: number
|
4 | }
|
5 |
|
6 | declare type Base64Url = string
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | declare type ImageUrl = string
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | export function getSizeOfUrl(url: ImageUrl): Promise<Size>
|
17 |
|
18 | /**
|
19 | * Whether the canvas is available in current browser
|
20 | * */
|
21 | export const canvasSupport: boolean
|
22 |
|
23 | declare type ImgType = ImageUrl | Base64Url | HTMLImageElement | File | FileList | Blob
|
24 |
|
25 | /**
|
26 | * Get the img size corresponding
|
27 | * */
|
28 | export function getNaturalSize(img: ImgType): Promise<Size>
|
29 |
|
30 | declare type CompressType =
|
31 | 'scale' | // Resize the image by `options.scale`
|
32 | 'fixedWidth' | // Set the width of the image to a fixed value -- `options.imageSize`
|
33 | 'fixedHeight' | // Set the height of the image to a fixed value -- `options.imageSize`
|
34 | 'fixedSize' // Set the smaller between width and height of the image to a fixed value -- `options.imageSize`
|
35 |
|
36 | declare interface CompressOptions {
|
37 | /**
|
38 | * Compress type, options: `compressTypes`
|
39 | *
|
40 | * default to 'scale'
|
41 | * */
|
42 | compressType?: CompressType
|
43 | /**
|
44 | * Scale factor, works when compressType is `scale`
|
45 | *
|
46 | * default to 1
|
47 | * */
|
48 | scale?: number
|
49 | /**
|
50 | * The fixed value of size,
|
51 | * works when compressType is `fixedWidth`, `fixedHeight` or `fixedSize`.
|
52 | * If imageSize is 0, it means convert to naturalSize
|
53 | *
|
54 | * default to 0
|
55 | * */
|
56 | imageSize?: number
|
57 | /**
|
58 | * The mine type of image returned
|
59 | *
|
60 | * default to the type of `imgFile` or 'image/png'
|
61 | * */
|
62 | imageType?: string
|
63 | /**
|
64 | * Compress quality, works when imageType is `image/jpeg` or `image/webp`
|
65 | *
|
66 | * default to 0.8
|
67 | * */
|
68 | quality?: number
|
69 | /**
|
70 | * If it is false, the promise returned will be resolved with a base64 string
|
71 | *
|
72 | * default to true
|
73 | * */
|
74 | toBlob?: boolean
|
75 | }
|
76 |
|
77 | /**
|
78 | * Compress image in browser
|
79 | * */
|
80 | export function imgCompress(imgFile: File | Blob, compressOptions: CompressOptions): Promise<Blob | Base64Url>
|
81 |
|
\ | No newline at end of file |