Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
loadImage(file, canvas => {
if (canvas.type === 'error') {
return alert('The image could not be loaded.')
}
const scaled = loadImage.scale(canvas, {
maxWidth: 400,
maxHeight: 300,
crop: true,
downsamplingRatio: 0.5,
})
scaled.toBlob(blob => {
this.setState({
imageURL: URL.createObjectURL(blob)
})
this.props.onSelect(blob)
}, 'image/jpeg')
}, {
// loadImage options
image.addEventListener('load', () => {
// using components/blueimp-load-image
// first, make the correct size
let canvas = loadImage.scale(image, {
canvas: true,
cover: true,
maxWidth: size,
maxHeight: size,
minWidth: size,
minHeight: size,
});
// then crop
canvas = loadImage.scale(canvas, {
canvas: true,
crop: true,
maxWidth: size,
maxHeight: size,
minWidth: size,
minHeight: size,
});
const blob = dataURLToBlobSync(canvas.toDataURL(contentType));
resolve(blob);
});
this.inputImageShape = [img.height, img.width]
const outputCanvas = document.getElementById('output-canvas')
outputCanvas.width = img.width * 2
outputCanvas.height = img.height * 2
this.outputImageShape = [img.height * 2, img.width * 2]
const scaledInputCanvas = document.getElementById('scaled-input-canvas')
scaledInputCanvas.width = img.width * 2
scaledInputCanvas.height = img.height * 2
// load image data onto input canvas
inputCanvas.getContext('2d').drawImage(img, 0, 0)
this.imageLoadingError = false
this.imageLoading = false
// bilinear scale input image to compare to
const scaledImg = loadImage.scale(img, { minWidth: img.width * 2, maxWidth: img.width * 2 })
scaledInputCanvas.getContext('2d').drawImage(scaledImg, 0, 0)
// run model
this.modelRunning = true
this.modelRunningError = false
this.$nextTick(function() {
setTimeout(() => {
this.runModel()
}, 10)
})
}
},
{ maxWidth: this.srcMaxWidth, canvas: true, crossOrigin: 'Anonymous' }
image.addEventListener('load', () => {
// using components/blueimp-load-image
// first, make the correct size
let canvas = loadImage.scale(image, {
canvas: true,
cover: true,
maxWidth: size,
maxHeight: size,
minWidth: size,
minHeight: size,
});
// then crop
canvas = loadImage.scale(canvas, {
canvas: true,
crop: true,
maxWidth: size,
maxHeight: size,
minWidth: size,
minHeight: size,