2

I'm using react-native-image-picker and I want to compress images in order to send them faster to my server.

Right now setting the option "quality" to 0.5 works just fine, but I don't want to compress small images too. I rather keep them untouched indeed.

How can I provide a condition which considers the current size of the file, then set the "quality" option to 0.5 , only if the size is larger than a specified amount (5MB for example)?

import ImagePicker from 'react-native-image-picker';

onPressGallery() {
            const option = {
                multiple: false,
                width: 1000,
                height: 500,
                quality: 0.5,
            };
            ImagePicker.launchImageLibrary(option, response => {
                {
                    console.log('onPressGallery', response);
                    const source = {uri: response.path};
                }
            });
        }

I really appreciate it if anyone could help.

Zeynab Rostami
  • 423
  • 4
  • 13

2 Answers2

2

I am using the showImagePicker function returned from 'react-native-image-picker' and having the same problem. What i did was add the (maxHeight: 600, maxWidth: 800) and it works.

enter image description here

Elikill58
  • 4,050
  • 24
  • 23
  • 45
JorgeW
  • 21
  • 2
-1

Response is returning bytes now, after that you can feed the image to ImageManipulator and apply the wished quality (compress prop from https://docs.expo.io/versions/v35.0.0/sdk/imagemanipulator/)

Egizas
  • 317
  • 2
  • 10