compress-base64
v6.1.1
Published
compress base64
Downloads
2,154
Readme
compress-base64
A library for compressing base64 in browser environment.
install
npm i compress-base64
or
yarn add compress-base64
or
pnpm add compress-base64
usage
options
es
For example.
import compress from 'compress-base64'
if (typeof FileReader === 'function') {
const reader = new FileReader()
reader.onload = event => {
compress(event.target.result, {
width: 400,
type: 'image/png',
max: 200, // max size
min: 20, // min size
quality: 0.8,
}).then(result => {
console.log(result)
})
}
reader.readAsDataURL(file)
} else {
alert('Your browser does not support FileReader')
}
browser
Introduce this resource.
<script src="https://unpkg.com/compress-base64@latest"></script>
You can also download this resource locally and then import it.
<script src="/path/compress-base64@latest"></script>
Use it.
if (typeof FileReader === 'function') {
const reader = new FileReader()
reader.onload = event => {
window.CompressBase64.default(event.target.result, {
width: 100,
type: 'image/png',
max: 7, // max size
min: 5,
quality: 0.8,
}).then(result => {
console.log(result.length)
resolve(result)
})
}
reader.readAsDataURL(file)
} else {
alert('Your browser does not support FileReader')
}