skip to Main Content

How to check the quality of image in react native like if I want to take 60%. Quality image so how to get it

I tried it through pixel resolution but it didn’t work

2

Answers


  1. If you are using react-native-image-picker for uploading images, you can set maxWidth, maxHeight or quality of image for reducing the size in options.

    const options = {
        title: 'Select Picture',
        storageOptions: {
            skipBackup: true,
            path: 'images',
        },
        maxWidth: 500,
        maxHeight: 500,
        quality: 0.5,
    };
    

    Or if you want to fit in the image in any View you can use resizeMode property of Image which has the type enum('cover', 'contain', 'stretch', 'repeat', 'center').

    Login or Signup to reply.
  2. you can user react-native-image-picker library and can restrict user for image quality to upload and you can edit rest of the parameters on the basis of your requirements.

    const result = await ImagePicker.launchImageLibraryAsync({
        mediaTypes: "Images",
        allowsEditing: true,
        base64: true,
        quality: 0.6,
    });
    
    if (!result.cancelled) {
        const fileSize = result.base64.length * (3 / 4) - 2;
        if (fileSize > 6000000) {
            setFileSizeError(true);
        } else {
            setFileSizeError(false);
            const base64 = `data:image/png;base64,${result.base64}`;
            await dispatch(myExampleAction(base64));
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search