Skip to content

Commit 227aeca

Browse files
authored
Merge pull request #183 from Donaldcwl/dev
v2.0.1 RC
2 parents b1959e0 + 5b0a08d commit 227aeca

38 files changed

+4070
-3781
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 2.0.1 (XX Mar 2023)
2+
* feature: preserve Exif metadata for JPEG [#164](https://github.com/Donaldcwl/browser-image-compression/issues/164)
3+
* feature: support BMP image compression [#181](https://github.com/Donaldcwl/browser-image-compression/issues/181)
4+
* optimized: solved error in sensible CSP environment [#106](https://github.com/Donaldcwl/browser-image-compression/issues/106)
5+
* optimized: increase initial PNG color depth to improve output quality [#180](https://github.com/Donaldcwl/browser-image-compression/issues/180)
6+
* fixed: circular dependency [#34](https://github.com/Donaldcwl/browser-image-compression/issues/34)
7+
* fixed: export Options interface [#157](https://github.com/Donaldcwl/browser-image-compression/issues/157)
8+
* fixed: black image output on iOS devices [#169](https://github.com/Donaldcwl/browser-image-compression/issues/169), [#165](https://github.com/Donaldcwl/browser-image-compression/issues/165), [#166](https://github.com/Donaldcwl/browser-image-compression/issues/166)
9+
110
## v2.0.0 (13 Apr 2022)
211
* feature: example html - added CSS animation for showing main thread status
312
* feature: example html - added version switch

README.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Javascript module to be run in the web browser for image compression.
77

88
## Features
9-
- You can use this module to compress jpeg and png images by reducing **resolution** or **storage size** before uploading to the application server to save bandwidth.
9+
- You can use this module to compress jpeg, png, webp, and bmp images by reducing **resolution** or **storage size** before uploading to the application server to save bandwidth.
1010
- **Multi-thread** (web worker) non-blocking compression is supported through options.
1111

1212

@@ -34,7 +34,7 @@ async function handleImageUpload(event) {
3434
const options = {
3535
maxSizeMB: 1,
3636
maxWidthOrHeight: 1920,
37-
useWebWorker: true
37+
useWebWorker: true,
3838
}
3939
try {
4040
const compressedFile = await imageCompression(imageFile, options);
@@ -98,7 +98,7 @@ You can download imageCompression from the [dist folder][dist].
9898

9999
Alternatively, you can use a CDN like [delivrjs]:
100100
```html
101-
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.0/dist/browser-image-compression.js"></script>
101+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.1/dist/browser-image-compression.js"></script>
102102
```
103103

104104

@@ -107,6 +107,8 @@ If this project helps you reduce the time to develop, you can buy me a cup of co
107107

108108
<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>
109109

110+
(powered by Stripe)
111+
110112
## API
111113
### Main function
112114
```javascript
@@ -118,8 +120,10 @@ const options: Options = {
118120
// Please check the Caveat part for details.
119121
onProgress: Function, // optional, a function takes one progress argument (percentage from 0 to 100)
120122
useWebWorker: boolean, // optional, use multi-thread web worker, fallback to run in main-thread (default: true)
123+
libURL: string, // optional, the libURL of this library for importing script in Web Worker (default: https://cdn.jsdelivr.net/npm/browser-image-compression/dist/browser-image-compression.js)
124+
preserveExif: boolean, // optional, use preserve Exif metadata for JPEG image e.g., Camera model, Focal length, etc (default: false)
121125

122-
signal: AbortSignal, // options, to abort / cancel the compression
126+
signal: AbortSignal, // optional, to abort / cancel the compression
123127

124128
// following options are for advanced users
125129
maxIteration: number, // optional, max number of iteration to compress the image (default: 10)
@@ -133,7 +137,7 @@ imageCompression(file: File, options: Options): Promise<File>
133137
```
134138

135139
#### Caveat
136-
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/>
140+
Each browser limits [the maximum size](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas#maximum_canvas_size) of a browser Canvas object. <br/>
137141
So, we resize the image to less than the maximum size that each browser restricts. <br/>
138142
(However, the `proportion/ratio` of the image remains.)
139143

@@ -175,6 +179,7 @@ imageCompression.drawImageInCanvas(img: HTMLImageElement, fileType?: string): HT
175179
imageCompression.drawFileInCanvas(file: File, options?: Options): Promise<[ImageBitmap | HTMLImageElement, HTMLCanvasElement | OffscreenCanvas]>
176180
imageCompression.canvasToFile(canvas: HTMLCanvasElement | OffscreenCanvas, fileType: string, fileName: string, fileLastModified: number, quality?: number): Promise<File>
177181
imageCompression.getExifOrientation(file: File): Promise<number> // based on https://stackoverflow.com/a/32490603/10395024
182+
imageCompression.copyExifWithoutOrientation(copyExifFromFile: File, copyExifToFile: File): Promise<File> // based on https://gist.github.com/tonytonyjan/ffb7cd0e82cb293b843ece7e79364233
178183
```
179184

180185

@@ -192,6 +197,9 @@ You can include the following script to load the core-js polyfill:
192197
<script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/3.21.1/minified.min.js"></script>
193198
```
194199

200+
### Webp support
201+
The webp compression is supported on major browsers. Please see https://caniuse.com/mdn-api_offscreencanvas_converttoblob_option_type_parameter_webp for browser compatibility.
202+
195203

196204
## Remarks for compression to work in Web Worker
197205
The browser needs to support "OffscreenCanvas" API in order to take advantage of non-blocking compression. If the browser does not support "OffscreenCanvas" API, the main thread is used instead. See https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas#browser_compatibility for browser compatibility of "OffscreenCanvas" API.
@@ -201,6 +209,14 @@ The browser needs to support "OffscreenCanvas" API in order to take advantage of
201209
Typescript definitions are included in the package & referenced in the `types` section of the `package.json`
202210

203211

212+
## Remarks on Content Security Policy (CSP)
213+
If your website has CSP enabled and you want to use Web Worker (useWebWorker: true), please add the following to the response header
214+
`content-security-policy: script-src 'self' blob: https://cdn.jsdelivr.net`
215+
216+
- `blob:` is for loading Web Worker script
217+
- `https://cdn.jsdelivr.net` is for importing this library from CDN inside Web Worker script. If you don't want to load this library from CDN, you can set your self hosted library URL in `options.libURL`.
218+
219+
204220
## Contribution
205221
1. fork the repo and git clone it
206222
2. run `npm run watch` # it will watch code change in lib/ folder and generate js in dist/ folder

example-express-server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ yarn dev
1515
## Sample frontend HTML
1616
```html
1717
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script>
18-
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.0/dist/browser-image-compression.js"></script>
18+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.1/dist/browser-image-compression.js"></script>
1919
<input type="file" accept="image/*" onchange="compressImage(event);">
2020
<script>
2121
function compressImage (event) {
Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)