Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed issue with IE support #56

Merged
merged 1 commit into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v1.0.11 (8 May 2020)
* fixed: issue with IE support [#38](https://github.com/Donaldcwl/browser-image-compression/issues/38) [#23](https://github.com/Donaldcwl/browser-image-compression/issues/23)

## v1.0.10 (7 May 2020)
* fixed: issue in Web Worker when onProgress is undefined [#50](https://github.com/Donaldcwl/browser-image-compression/issues/50)
* fixed: handle behavior change of exif orientation in iOS 13.4.1 and Safari 13.1 Desktop [#52](https://github.com/Donaldcwl/browser-image-compression/issues/52)
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ or check the "[example]" folder in this repo
| --------- | --------- | --------- | --------- | --------- | --------- |
| IE10, IE11, Edge| last 2 versions| last 2 versions| last 2 versions| last 2 versions| last 2 versions

## IE support ##
Promise API is being used in this library. If you need to support browser that do not support Promise like IE. You can include the Promise polyfill in your project.

See: https://github.com/taylorhakes/promise-polyfill

You can include the following script to load the Promise polyfill:
```html
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script>
```

## Typescript type definitions ##
```
npm install --save-dev @types/browser-image-compression
Expand Down
20 changes: 12 additions & 8 deletions example/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@


<script>
async function compressImage (event, useWebWorker) {
function compressImage (event, useWebWorker) {
var file = event.target.files[0]
var logDom, progressDom
if (useWebWorker) {
Expand All @@ -65,20 +65,23 @@

logDom.innerHTML = 'Source image size:' + (file.size / 1024 / 1024).toFixed(2) + 'mb'
console.log('input', file)
console.log('ExifOrientation', await imageCompression.getExifOrientation(file))
imageCompression.getExifOrientation(file).then(function (o) {
console.log('ExifOrientation', o)
})

var options = {
maxSizeMB: parseFloat(document.querySelector('#maxSizeMB').value),
maxWidthOrHeight: parseFloat(document.querySelector('#maxWidthOrHeight').value),
useWebWorker: useWebWorker,
onProgress: onProgress
}
const output = await imageCompression(file, options)
logDom.innerHTML += ', output size:' + (output.size / 1024 / 1024).toFixed(2) + 'mb'
console.log('output', output)
const downloadLink = URL.createObjectURL(output)
logDom.innerHTML += '&nbsp;<a href="' + downloadLink + '" download="' + file.name + '">download compressed image</a>'
document.getElementById('preview-after-compress').src = downloadLink
imageCompression(file, options).then(function (output) {
logDom.innerHTML += ', output size:' + (output.size / 1024 / 1024).toFixed(2) + 'mb'
console.log('output', output)
const downloadLink = URL.createObjectURL(output)
logDom.innerHTML += '&nbsp;<a href="' + downloadLink + '" download="' + file.name + '">download compressed image</a>'
document.getElementById('preview-after-compress').src = downloadLink
})

// await uploadToServer(output)

Expand All @@ -96,6 +99,7 @@
})
}
</script>
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/browser-image-compression.js"></script>
</body>
</html>
21 changes: 13 additions & 8 deletions example/development.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@


<script>
async function compressImage (event, useWebWorker) {
function compressImage (event, useWebWorker) {
var file = event.target.files[0]
var logDom, progressDom
if (useWebWorker) {
Expand All @@ -65,20 +65,24 @@

logDom.innerHTML = 'Source image size:' + (file.size / 1024 / 1024).toFixed(2) + 'mb'
console.log('input', file)
console.log('ExifOrientation', await imageCompression.getExifOrientation(file))
imageCompression.getExifOrientation(file).then(function (o) {
console.log('ExifOrientation', o)
})

var options = {
maxSizeMB: parseFloat(document.querySelector('#maxSizeMB').value),
maxWidthOrHeight: parseFloat(document.querySelector('#maxWidthOrHeight').value),
useWebWorker: useWebWorker,
onProgress: onProgress
}
const output = await imageCompression(file, options)
logDom.innerHTML += ', output size:' + (output.size / 1024 / 1024).toFixed(2) + 'mb'
console.log('output', output)
const downloadLink = URL.createObjectURL(output)
logDom.innerHTML += '&nbsp;<a href="' + downloadLink + '" download="' + file.name + '">download compressed image</a>'
document.getElementById('preview-after-compress').src = downloadLink
imageCompression(file, options).then(function (output) {
logDom.innerHTML += ', output size:' + (output.size / 1024 / 1024).toFixed(2) + 'mb'
console.log('output', output)
const downloadLink = URL.createObjectURL(output)
logDom.innerHTML += '&nbsp;<a href="' + downloadLink + '" download="' + file.name + '">download compressed image</a>'
document.getElementById('preview-after-compress').src = downloadLink
})


// await uploadToServer(output)

Expand All @@ -96,6 +100,7 @@
})
}
</script>
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script>
<script type="text/javascript" src="../dist/browser-image-compression.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export function handleMaxWidthOrHeight (canvas, options) {
const height = canvas.height
const maxWidthOrHeight = options.maxWidthOrHeight

const needToHandle = Number.isFinite(maxWidthOrHeight) && (width > maxWidthOrHeight || height > maxWidthOrHeight)
const needToHandle = isFinite(maxWidthOrHeight) && (width > maxWidthOrHeight || height > maxWidthOrHeight)

let newCanvas = canvas
let ctx
Expand Down
2 changes: 2 additions & 0 deletions lib/web-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ export function compressOnWebWorker (file, options) {
}

worker.addEventListener('message', handler)
worker.addEventListener('error', reject)

worker.postMessage({
file,
id,
Expand Down