So I'm using react-native-signature-capture to capture a signature, but I wan't to cut down on the image size before encoding it. I used https://github.com/bamlab/react-native-image-resizer to resize the image, but now I don't know how to convert it to base64. I tried using RN's ImageStore but I get an error with the filepath of the image. See below for the code:
ImageResizer.createResizedImage(encoded.pathName, 200, 100, 'PNG', 80, null, encoded.pathName)
.then((resizedImageUrl) => {
ImageStore.getBase64ForTag(resizedImageUrl, (data) => {
console.log(data);
}, (err) => console.log(err));
})
.catch((err) => console.log('failed to resize: ' + err));
Solved this a while ago and forgot to put what I did until now, I basically used the library above and react-native-fs
to resize and retrieve the image as a base64:
handleBase64 = async (path) => {
const resizedImageUrl = await ImageResizer.createResizedImage(path, 200, 80, 'PNG', 80, 0, RNFS.DocumentDirectoryPath);
const base64 = await RNFS.readFile(resizedImageUrl, 'base64');
return base64;
}
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