could you help me how can I get output (source of cropped image) via react-image-crop module? Upload component looks like this:
class MyUpload extends Component {
constructor() {
super();
this.state = {
src: 'source-to-image',
crop: {
x: 10,
y: 10,
aspect: 9 / 16,
width: 100
}
}
}
onCropComplete = (crop, pixelCrop) => {
this.setState({
crop
})
};
render() {
return (
<ReactCrop
src={this.state.src}
onComplete={this.onCropComplete}
/>
);
} }
Method onCropComplete returns only coordinates, width and height of cropped image, not source. I would like to get blob file.
EDIT (working solution -- thanks for Mosè Raguzzini reply):
If someone has similiar problem, call getCropptedImg function from tutorial in your component and create url from returned Blob object, like this:
getCroppedImg(this.state.image, pixelCrop, 'preview.jpg')
.then((res) => {
const blobUrl = URL.createObjectURL(res);
console.log(blobUrl); // it returns cropped image in this shape of url: "blob:http://something..."
})