onurzorluer / react-image-file-resizer

Resize Local Images with React 🌄 🌅
MIT License
317 stars 41 forks source link

Target file size #21

Open zehawki opened 4 years ago

zehawki commented 4 years ago

Hello, may I make a feature request - take a target file size as a prop, and allow fixing 1 or more levers to achieve roughly that file size.

I.e. file size is a result of 2 levers - resolution and compression in case of JPG. So we could set resolution as fixed, while the compression can be auto varied to hit (around) target file size. Or vice versa - i.e. compression is fixed, while the resolution can be auto changed. Or both can be varied, etc etc.

A small iterative algo could loop through some trials and provide the best fit within say 5 trials or some such. Obviously this can be implemented outside this component, and just iteratively call the component with different params till the size is achieved, but why not bake this inside your component?

I would imagine this is a rather standard usecase for uploading images, and a robust solution would be quite beneficial.