5

I'm using react native image picker and image resizer to pick and then resize an image. How do I get the base64 of the image once it has been resized?

ImagePickerManager.showImagePicker(imagepicker_options, (response) => { ImageResizer.createResizedImage(response.uri, 550, null, 'JPEG', 100).then((resizedImageUri) => { //get base64 of image }); }); 

2 Answers 2

4

https://libraries.io/npm/react-native-asset-library-to-base64

ImagePickerManager.showImagePicker(imagepicker_options, (response) => { ImageResizer.createResizedImage(response.uri, 550, null, 'JPEG', 100).then((resizedImageUri) => { //get base64 of image, uri is link to asset-library:// ReadImageData.readImage(uri, (imageBase64) => { console.log(imageBase64); }); }); }); 

you might also want to read this if you haven't https://github.com/facebook/react-native/issues/1158

Sign up to request clarification or add additional context in comments.

3 Comments

What about Android?
There is an issue said that it does not work on Android 0.49. github.com/xfumihiro/react-native-image-to-base64/issues/11. Please update it, thank you
0

Actually the imagepicker_options provides a way to resize. You can pass maxWidth and maxHeight on options.

The code:

const imagepicker_options = { mediaType: 'photo', maxWidth: 550, storageOptions: { skipBackup: true, cameraRoll: false, path: 'images', }, } ImagePickerManager.showImagePicker(imagepicker_options, (response) => { //get base64 of image const base64 = response.data }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.