Dkpalea
Dkpalea

Reputation: 13

Are there any libraries for use with react native and expo that can compress an image to a target file size?

I'm building an app with react native and expo (managed). I'm trying to compress images to a specific file size but can only find libraries that allow me to set a "quality" setting (which compresses images to some arbitrary size).

Are there any libraries like browser-image-compression that allow me to set a "target" image size, for use with react native and expo?

(Or is there some other way I might accomplish this?)

Upvotes: 0

Views: 418

Answers (1)

Romeo Ninov
Romeo Ninov

Reputation: 7245

The size of the image depend of many factors like level of compression, amount of details, number of colours in the image, algorithm of compression. So there is no way directly to define the image size and compress it. What you can do is to define level of compression somewhere in the middle do test compression, check if the size is above or below defined value and change accordingly the level of compression. And try again until you get desired size.

Upvotes: 0

Related Questions