Pressor is a tool to compress images to target size via canvas in browser
npm install pressor
# or
yarn add pressor
# or
pnpm add pressor
compress:
The function signature of compress
is:
function compress(file: File, limit: number, accuracy: number): Promise<File>;
file
: the image file which will be compressedlimit
: the target size of the compressed file in kb, default to500
accuracy
: the accuracy of produced file size, default to0.8
example:
import { compress } from 'pressor';
const inputChangeHandler = async (evt) => {
const file = evt.target.files[0];
const result = await compress(file);
};