Without limiting the user to specific file sizes, users can upload a file or document from the frontend to the backend server; image resizer will handle the resizing without losing its quality.
This package can be installed using npm
npm i @clefayomide/image-resizer
or, yarn
yarn add @clefayomide/image-resizer
Import image_resize
import { image_resize } from '@clefayomide/image-resizer';
Wrapping things up
const file = e.target.files[0];
image_resize(file, 500)
.then(res => {
// perform an action with the resized file, such as sending to server
})
.catch(err => console.error(err));
Available props:
Argument | Description | type |
---|---|---|
file |
the file to be resized | File |
width |
the required width for the new file | number |
If any issues are found, they can be reported here.
This project is licensed under the MIT license.