Skip to content

Instantly share code, notes, and snippets.

@hungtrn75
Created June 23, 2021 13:39
Show Gist options
  • Save hungtrn75/13e3071130e65cf376ffe89bf25fc657 to your computer and use it in GitHub Desktop.
Save hungtrn75/13e3071130e65cf376ffe89bf25fc657 to your computer and use it in GitHub Desktop.
Rotate image
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