I thought i might also share my resolution to this issue, Thanks to @shuffgy’s code above, slightly modified to save a base64 string inside of a pouch db without android killing the sync process.
In addition, it also checks for the permission to access the camera roll as well, which is an often missed step.
_pickImage = async () => {
//prompt for camera permission
const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (status === 'granted') {
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: 'Images',
allowsEditing: false
});
// console.log(result);
if (!result.cancelled) {
var wantedMaxSize = 1280;
var rawheight = result.height;
var rawwidth = result.width;
var ratio = rawwidth / rawheight;
// check vertical or horizont
if(rawheight > rawwidth){
var wantedwidth = wantedMaxSize*ratio;
var wantedheight = wantedMaxSize;
}
else {
var wantedwidth = wantedMaxSize;
var wantedheight = wantedMaxSize/ratio;
}
let resizedBase64 = await new Promise((resolve, reject) => {
ImageEditor.cropImage(result.uri,
{
offset: { x: 0, y: 0 },
size: { width: result.width, height: result.height },
displaySize: { width: wantedwidth, height: wantedheight },
resizeMode: 'contain',
},
(uri) => {
ImageStore.getBase64ForTag(uri,
(base64Data) => {
resolve('data:image/jpg'+ ';base64,' + base64Data);
},
(reason) => reject(reason));
},
() => reject());
});
console.log(resizedBase64);
//store resizedBase64 in db
}
}
}```