* compress avatar images before upload * move compressImage to dedicated file * Update ImageUpload.js
18 lines
363 B
JavaScript
18 lines
363 B
JavaScript
// @flow
|
|
import Compressor from "compressorjs";
|
|
|
|
type Options = Omit<Compressor.Options, "success" | "error">;
|
|
|
|
export const compressImage = async (
|
|
file: File | Blob,
|
|
options?: Options
|
|
): Promise<Blob> => {
|
|
return new Promise((resolve, reject) => {
|
|
new Compressor(file, {
|
|
...options,
|
|
success: resolve,
|
|
error: reject,
|
|
});
|
|
});
|
|
};
|