Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
formatOutput (imageData) {
if (this.debug) {
console.log('ImageUploader: outputFormat: ' + this.outputFormat)
}
if (this.outputFormat === 'blob') {
if (typeof dataURLtoBlob === 'undefined') {
console.warn('Missing library! blueimp-canvas-to-blob.js must be loaded to output as "blob"')
console.warn('Falling back to default base64 dataUrl')
return imageData
}
return dataURLtoBlob(imageData)
}
if (this.outputFormat === 'verbose') {
return {
dataUrl: imageData,
name: this.currentFile.name,
lastModified: this.currentFile.lastModified,
lastModifiedDate: this.currentFile.lastModifiedDate
}
}
// simple base64 dataUrl string by default
return imageData
}
},
formatOutput: function formatOutput (imageData) {
if (this.debug) {
console.log('ImageUploader: outputFormat: ' + this.outputFormat);
}
if (this.outputFormat === 'blob') {
if (typeof dataURLtoBlob === 'undefined') {
console.warn('Missing library! blueimp-canvas-to-blob.js must be loaded to output as "blob"');
console.warn('Falling back to default base64 dataUrl');
return imageData
}
return dataURLtoBlob(imageData)
}
if (this.outputFormat === 'verbose') {
return {
dataUrl: imageData,
name: this.currentFile.name,
lastModified: this.currentFile.lastModified,
lastModifiedDate: this.currentFile.lastModifiedDate
}
}
// simple base64 dataUrl string by default
return imageData
}
},
formatOutput(imageData) {
this.log('ImageUploader: outputFormat: ' + this.outputFormat)
if (this.outputFormat === 'file') {
return this.currentFile
}
if (this.outputFormat === 'blob') {
if (typeof dataURLtoBlob === 'undefined') {
console.warn('Missing library! blueimp-canvas-to-blob.js must be loaded to output as "blob"')
console.warn('Falling back to default base64 dataUrl')
return imageData
}
return dataURLtoBlob(imageData)
}
const info = {
name: this.currentFile.name,
type: this.currentFile.type,
// size: this.currentFile.size,
newWidth: this.dimensions.width,
newHeight: this.dimensions.height,
orgWidth: this.dimensions.orgWidth,
orgHeight: this.dimensions.orgHeight,
aspectRatio: Math.round((this.dimensions.width / this.dimensions.height) * 100) / 100, //as Float
modifiedTimestamp: this.currentFile.lastModified,
modifiedDate: this.currentFile.lastModifiedDate,
}
// return just info
}
// Converts PNG files over the `convertSize` to JPEGs.
if (file.size > options.convertSize && options.mimeType === 'image/png') {
options.mimeType = 'image/jpeg';
}
// If the output image is JPEG
if (options.mimeType === 'image/jpeg') {
// Override the default fill color (#000, black) with #fff (white)
context.fillStyle = '#fff';
context.fillRect(0, 0, canvasWidth, canvasHeight);
}
context.drawImage(image, 0, 0, canvasWidth, canvasHeight);
if (canvas.toBlob) {
canvas.toBlob(resolve, options.mimeType, options.quality);
} else {
resolve(toBlob(canvas.toDataURL(options.mimeType, options.quality)));
}
});
}
const done = (result) => {
if (!this.aborted) {
this.done({
naturalWidth,
naturalHeight,
result,
});
}
};
if (canvas.toBlob) {
canvas.toBlob(done, options.mimeType, options.quality);
} else {
done(toBlob(canvas.toDataURL(options.mimeType, options.quality)));
}
}
}
context.restore();
const done = (result) => {
resolve({
naturalWidth,
naturalHeight,
result,
});
};
if (canvas.toBlob) {
canvas.toBlob(done, options.mimeType, options.quality);
} else {
done(toBlob(canvas.toDataURL(options.mimeType, options.quality)));
}
}))
.then(({