Skip to content

Commit

Permalink
restore to previous commit + Image crop improvement
Browse files Browse the repository at this point in the history
Using a variant of react-native-perspective-image-cropper:
Michaelvilleneuve/react-native-perspective-image-cropper#37
C:\Users\lyous\OneDrive\Desktop\Github\Custom-Modules\react-native-perspective-image-cropper
  • Loading branch information
meliodev committed May 5, 2021
1 parent 480a923 commit 243fb86
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 4 deletions.
4 changes: 1 addition & 3 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ export default class App extends Component {
handlerColor="rgba(20,150,160, 1)"
enablePanStrict={false}
/>
<TouchableOpacity onPress={this.crop.bind(this)} style={{ marginTop: 50 }}>
<Text>CROP IMAGE</Text>
</TouchableOpacity>

</View>
)
}
Expand Down
96 changes: 96 additions & 0 deletions ImageCrop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@


import CustomCrop from "react-native-perspective-image-cropper";
import ImagePicker from 'react-native-image-picker'

class App extends Component {

constructor(props) {
super(props)

this.state = {
image: null,
path: '',
rectangleCoordinates: {
topLeft: { x: 50, y: 50 },
topRight: { x: 50, y: 50 },
bottomRight: { x: 50, y: 50 },
bottomLeft: { x: 50, y: 50 }
}
}
}

componentDidMount() {

const imagePickerOptions = {
title: 'Selectionner une image',
takePhotoButtonTitle: 'Prendre une photo',
chooseFromLibraryButtonTitle: 'Choisir de la librairie',
cancelButtonTitle: 'Annuler',
noData: true,
mediaType: 'photo'
}


ImagePicker.launchCamera(imagePickerOptions, 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.camera);

else {

const path = Platform.OS === 'android' ? response.path : response.uri //try without file://

this.setState({
path,
imageWidth: response.width,
imageHeight: response.height,
image: response.uri,
})
}

})

}

updateImage(image, newCoordinates) {
image = `data:image/jpeg;base64,${image}`
Image.getSize(image, () => {

})
this.setState({
image,
rectangleCoordinates: newCoordinates
});
}

crop() {
this.customCrop.crop();
}

render() {
const { image, imageHeight, imageWidth, path } = this.state

if (!image || !imageWidth || !imageHeight || !path) return null

return (
<View>
<CustomCrop
updateImage={this.updateImage.bind(this)}
//rectangleCoordinates={this.state.rectangleCoordinates}
initialImage={this.state.image}
path={this.state.path}
height={this.state.imageHeight}
width={this.state.imageWidth}
ref={ref => (this.customCrop = ref)}
overlayColor="rgba(18,190,210, 1)"
overlayStrokeColor="rgba(20,190,210, 1)"
handlerColor="rgba(20,150,160, 1)"
enablePanStrict={false}
/>
</View>
)
}
}

2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
buildscript {
ext {
buildToolsVersion = "29.0.2"
minSdkVersion = 16
minSdkVersion = 19
compileSdkVersion = 29
targetSdkVersion = 29
}
Expand Down

0 comments on commit 243fb86

Please sign in to comment.