const blitz = Blitz.create()
blitz({
source: DOM Image/DOM Canvas/jQuery/DataURL/File,
width: 400,
height: 600
}).then(output => {
}).catch(error => {
})
let resized = await blizt({...})
const blitz = Blitz.create('callback')
blitz({...}, function(output) {
})
Precipitously cut image upload time and server loads by doing client-side image resizing. Blitz is non-blocking so you will not experience UI freeze when it is resizing. Advanced scaling options with max or min height/width.
blitz({
source: DOM Image/DOM Canvas/jQuery/DataURL/Javscript #File,
width: (number),
height: (number),
maxWidth: (number),
maxHeight: (number),
minWidth: (number),
minHeight: (number),
proportional: true (default)/false,
outputFormat: 'jpg',
output: 'data',
quality: 0.7,
logPerformance: true/false
}).then(output => {
}).catch(err => {
})
<input type="file" capture="camera" accept="image/*" id="cameraInput" name="cameraInput">
<script>
function readFile(file) {
var reader = new FileReader();
reader.onload = readSuccess;
function readSuccess(evt) {
var bAwait = Blitz.create()
try {
let output = await bAwait({
source: evt.target.result,
width: 400,
height: 600,
outputFormat: 'jpg',
output: 'data',
quality: 0.7,
logPerformance: true,
proportional: true
})
console.log('Resize using event successful')
var image = new Image()
image.src = data
document.getElementByTag('body').append(image)
} catch(err) {
console.log(err)
}
var img = new Image()
img.src = evt.target.result
var bPromise = Blitz.create()
img.onload = function() {
bPromise.resize({
source: img,
width: 400,
outputFormat: 'jpg',
output: 'canvas',
quality: 0.7,
logPerformance: true
}).then(canvas => {
console.log('Resize using img to canvas successful')
document.getElementByTag('body').append(canvas)
})
}
var bCallback = Object.create(Blitz)
bCallback.resize({
source: evt.target.result,
maxWidth: 640,
minHeight: 400,
outputFormat: 'jpg',
output: 'image',
quality: 0.7,
logPerformance: true
}, function(image) {
console.log('Resize using data successful')
document.getElementByTag('body').append(image)
})
};
reader.readAsDataURL(file);
}
document.getElementById('cameraInput').onchange = function(e) {
var b5 = Blitz.create()
b5({
source: e.srcElement.files[0],
minHeight: 600,
outputFormat: 'jpg',
quality: 0.7,
logPerformance: true
}).then(download => {
console.log('Resize using file successful')
download()
}).catch(err => {
console.log(err)
})
readFile(e.srcElement.files[0]);
};
</script>