This approach worked in my case, but the output seems a bit odd to me
if (isFile(input)) {
const file = new File([blob], input.name)
resolve(file as T)
} else if (isBlob(input)) {
resolve(blob as T)
}
excerpted from:
export
function adjustSize<T extends Blob | File>(input: T, width: number, height: number): Promise<T> {
return new Promise((resolve, reject) => {
const image = new Image()
image.onload = () => {
const canvas = document.createElement('canvas')
canvas.width = width
canvas.height = height
pica.resize(image, canvas)
.then((result) => pica.toBlob(result, input.type, 85))
.then((blob: Blob) => {
if (isFile(input)) {
const file = new File([blob], input.name)
resolve(file as T)
} else if (isBlob(input)) {
resolve(blob as T)
}
})
.catch(err => reject(err))
}
image.src = URL.createObjectURL(input)
})
}