Donaldcwl / browser-image-compression

Image compression in web browser
MIT License
1.3k stars 160 forks source link

Explanation #99

Closed msaad1311 closed 3 years ago

msaad1311 commented 3 years ago

Hi. First off, hats off to the amazing work. It is a real life saver. Nevertheless, I am curious to know the underlying working of the algorithm. In order words, I am curious to know how the compression of the images take place?

Looking forward to hearing from you soon. Thanks.

Donaldcwl commented 3 years ago

@msaad1311 Thanks for using this library. This library reduces the image width, height, or quality iteratively to meet the maxSizeMB and maxWidthOrHeight requirements. We make use of the Canvas API to do image processing. https://github.com/Donaldcwl/browser-image-compression/blob/7d633972e66f94d469789c806f5302397994b63a/lib/image-compression.js#L88-L107

Multi-thread non-blocking compression is supported through options that make use of Web Worker to handle Canvas processing outside the main thread. So the UI will not be "hang" when compressing the image.