reduce the size of images with JPEG extension
It is for frontend application use
npm i compress-ali
pnpm i compress-ali
Code:
import { compressImage } from "compress-ali";
const file:File | null = null
// send only the file
const newFile = await compressImage(file!);
//more parameters: quality:[0.2 - 0.6](recommendation default 0.2), type: (its file.type)
const newFile = await compressImage(file,0.5,"image/jpeg");
the actual range is [0.1 - 1]
The quality loss is very large at 0.1, and from 0.7 the behavior will not be as expected, it may increase.
For now, it compresses image files with a jpg extension. Using other image formats will not reduce the size; on the contrary, it may increase.
".png,.jpg,.jpeg,.pdf,.gif"