Created
June 23, 2021 13:39
-
-
Save hungtrn75/13e3071130e65cf376ffe89bf25fc657 to your computer and use it in GitHub Desktop.
Rotate image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const onChangeAvatar = () => { | |
const options = { | |
takePhotoButtonTitle: 'Take Photo', | |
chooseFromLibraryButtonTitle: 'Choose Photo', | |
customButtons: [{name: 'Delete Photo', title: 'Delete Photo'}], | |
storageOptions: { | |
skipBackup: true, | |
path: 'images', | |
}, | |
rotation: 360, | |
}; | |
ImagePicker.showImagePicker(options, async (response) => { | |
if (response.didCancel) { | |
console.log('User cancelled image picker'); | |
} else if (response.error) { | |
console.log('ImagePicker Error: ', response.error); | |
} else if (response.customButton) { | |
console.log('User tapped custom button: ', response.customButton); | |
updateAvatar(null); | |
} else { | |
console.log(response); | |
const {uri, originalRotation} = response; | |
let rotation = 0; | |
if (originalRotation === 90) { | |
rotation = 90; | |
} else if (originalRotation === 270) { | |
rotation = -90; | |
} | |
const compressedImg = await ImageResizer.createResizedImage( | |
uri, | |
1000, | |
1000, | |
'JPEG', | |
80, | |
); | |
updateAvatar(compressedImg.uri); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment