Skip to content

Commit 909e24b

Browse files
committed
chore: update readme
1 parent 08ad440 commit 909e24b

File tree

1 file changed

+44
-47
lines changed

1 file changed

+44
-47
lines changed

README.md

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ Javascript module to be run in the web browser for image compression.
88
## Features ##
99
- You can use this module to compress jpeg and png image by reducing **resolution** or **storage size** before uploading to application server to save bandwidth.
1010
- **Multi-thread** (web worker) non-blocking compression are supported through options.
11+
## Demo / Example ##
12+
open https://donaldcwl.github.io/browser-image-compression/example/basic.html
1113

14+
or check the "[example]" folder in this repo
1215
## Install ##
1316
You can download imageCompression from the [dist folder][dist]. Alternatively, you can install it via yarn or npm
1417
```
@@ -23,11 +26,6 @@ or
2326
https://cdn.jsdelivr.net/npm/browser-image-compression@latest/dist/browser-image-compression.js
2427
```
2528

26-
## Support
27-
If this project help you reduce time to develop, you can buy me a cup of coffee :)
28-
29-
<a href="https://www.buymeacoffee.com/donaldcwl" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-red.png" alt="Buy Me A Coffee" height=60 width=217 ></a>
30-
3129
## How to use this module in your project? ##
3230
#### Use as ES module ####
3331

@@ -45,45 +43,6 @@ or
4543
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/browser-image-compression@1.0.17/dist/browser-image-compression.js"></script>
4644
```
4745

48-
## API ##
49-
### Main function ###
50-
```javascript
51-
// you should provide one of maxSizeMB, maxWidthOrHeight in the options
52-
const options: Options = {
53-
maxSizeMB: number, // (default: Number.POSITIVE_INFINITY)
54-
maxWidthOrHeight: number, // compressedFile will scale down by ratio to a point that width or height is smaller than maxWidthOrHeight (default: undefined)
55-
// but, automatically reduce the size to smaller than the maximum Canvas size supported by each browser.
56-
// Please check the Caveat part for details.
57-
onProgress: Function, // optional, a function takes one progress argument (percentage from 0 to 100)
58-
useWebWorker: boolean, // optional, use multi-thread web worker, fallback to run in main-thread (default: true)
59-
60-
// following options are for advanced users
61-
maxIteration: number, // optional, max number of iteration to compress the image (default: 10)
62-
exifOrientation: number, // optional, see https://stackoverflow.com/a/32490603/10395024
63-
fileType: string, // optional, fileType override
64-
initialQuality: number // optional, initial quality value between 0 and 1 (default: 1)
65-
}
66-
67-
imageCompression(file: File, options: Options): Promise<File>
68-
```
69-
70-
#### Caveat ####
71-
Each browser limits [the maximum size](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas#maximum_canvas_size) of a Canvas object. <br/>
72-
So, we resize the image to less than the maximum size that each browser restricts. <br/>
73-
(However, the `proportion/ratio` of the image remains.)
74-
75-
### Helper function ###
76-
- for advanced users only, most users won't need to use the helper functions
77-
```javascript
78-
imageCompression.getDataUrlFromFile(file: File): Promise<base64 encoded string>
79-
imageCompression.getFilefromDataUrl(dataUrl: string, filename: string, lastModified?: number): Promise<File>
80-
imageCompression.loadImage(url: string): Promise<HTMLImageElement>
81-
imageCompression.drawImageInCanvas(img: HTMLImageElement, fileType?: string): HTMLCanvasElement | OffscreenCanvas
82-
imageCompression.drawFileInCanvas(file: File, options?: Options): Promise<[ImageBitmap | HTMLImageElement, HTMLCanvasElement | OffscreenCanvas]>
83-
imageCompression.canvasToFile(canvas: HTMLCanvasElement | OffscreenCanvas, fileType: string, fileName: string, fileLastModified: number, quality?: number): Promise<File>
84-
imageCompression.getExifOrientation(file: File): Promise<number> // based on https://stackoverflow.com/a/32490603/10395024
85-
```
86-
8746
## Usage ##
8847
```html
8948
<input type="file" accept="image/*" onchange="handleImageUpload(event);">
@@ -139,10 +98,48 @@ function handleImageUpload(event) {
13998
}
14099
```
141100

142-
## Demo / Example ##
143-
open https://donaldcwl.github.io/browser-image-compression/example/basic.html
101+
## Support
102+
If this project help you reduce time to develop, you can buy me a cup of coffee :)
144103

145-
or check the "[example]" folder in this repo
104+
<a href="https://donaldcwl.github.io/donation/" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-red.png" alt="Buy Me A Coffee" height=60 width=217 ></a>
105+
## API ##
106+
### Main function ###
107+
```javascript
108+
// you should provide one of maxSizeMB, maxWidthOrHeight in the options
109+
const options: Options = {
110+
maxSizeMB: number, // (default: Number.POSITIVE_INFINITY)
111+
maxWidthOrHeight: number, // compressedFile will scale down by ratio to a point that width or height is smaller than maxWidthOrHeight (default: undefined)
112+
// but, automatically reduce the size to smaller than the maximum Canvas size supported by each browser.
113+
// Please check the Caveat part for details.
114+
onProgress: Function, // optional, a function takes one progress argument (percentage from 0 to 100)
115+
useWebWorker: boolean, // optional, use multi-thread web worker, fallback to run in main-thread (default: true)
116+
117+
// following options are for advanced users
118+
maxIteration: number, // optional, max number of iteration to compress the image (default: 10)
119+
exifOrientation: number, // optional, see https://stackoverflow.com/a/32490603/10395024
120+
fileType: string, // optional, fileType override
121+
initialQuality: number // optional, initial quality value between 0 and 1 (default: 1)
122+
}
123+
124+
imageCompression(file: File, options: Options): Promise<File>
125+
```
126+
127+
#### Caveat ####
128+
Each browser limits [the maximum size](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas#maximum_canvas_size) of a Canvas object. <br/>
129+
So, we resize the image to less than the maximum size that each browser restricts. <br/>
130+
(However, the `proportion/ratio` of the image remains.)
131+
132+
### Helper function ###
133+
- for advanced users only, most users won't need to use the helper functions
134+
```javascript
135+
imageCompression.getDataUrlFromFile(file: File): Promise<base64 encoded string>
136+
imageCompression.getFilefromDataUrl(dataUrl: string, filename: string, lastModified?: number): Promise<File>
137+
imageCompression.loadImage(url: string): Promise<HTMLImageElement>
138+
imageCompression.drawImageInCanvas(img: HTMLImageElement, fileType?: string): HTMLCanvasElement | OffscreenCanvas
139+
imageCompression.drawFileInCanvas(file: File, options?: Options): Promise<[ImageBitmap | HTMLImageElement, HTMLCanvasElement | OffscreenCanvas]>
140+
imageCompression.canvasToFile(canvas: HTMLCanvasElement | OffscreenCanvas, fileType: string, fileName: string, fileLastModified: number, quality?: number): Promise<File>
141+
imageCompression.getExifOrientation(file: File): Promise<number> // based on https://stackoverflow.com/a/32490603/10395024
142+
```
146143

147144
## Browsers support
148145

0 commit comments

Comments
 (0)