Photos captured via camera are too large for efficient upload and download in React native.
Is there an api or library to compress a PNG image file in React Native?
We can resize, compress and convert the images based on our requirements. To compress your images follow these three simple steps: Install the package using npm/yarn. Add the particular code block to your project.
If you are using react-native-image-picker for uploading images, you can set maxWidth, maxHeight or quality of image for reducing the size.
const options = {
title: 'Select Picture',
storageOptions: {
skipBackup: true,
path: 'images',
},
maxWidth: 500,
maxHeight: 500,
quality: 0.5
};
ImagePicker.showImagePicker(options, resolve, reject);
https://github.com/bamlab/react-native-image-resizer provides an API to resize local images.
It allows you to specify:
API
import ImageResizer from 'react-native-image-resizer';
ImageResizer.createResizedImage(imageUri, newWidth, newHeight, compressFormat, quality).then((resizedImageUri) => {
// resizeImageUri is the URI of the new image that can now be displayed, uploaded...
}).catch((err) => {
// Oops, something went wrong. Check that the filename is correct and
// inspect err to get more details.
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With