Created
October 13, 2021 22:04
-
-
Save OlivierJM/db921cae9116e78b37ea58633cdd1712 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import React, { useState } from 'react' | |
import Cropper from 'react-easy-crop' | |
import { getCroppedImg } from '../../../utils/helpers' | |
export default function ImageCropper({ getBlob, inputImg, fileName }){ | |
const [crop, setCrop] = useState({ x: 0, y: 0 }) | |
const [zoom, setZoom] = useState(1) | |
const onCropComplete = async (_, croppedAreaPixels) => { | |
const croppedImage = await getCroppedImg( | |
inputImg, | |
croppedAreaPixels | |
) | |
croppedImage.name = fileName | |
getBlob(croppedImage) | |
} | |
return( | |
<> | |
<div style={{height: '150px', marginLeft: '140px'}}> | |
<Cropper | |
image={inputImg} | |
crop={crop} | |
zoom={zoom} | |
aspect={4/1} | |
onCropChange={setCrop} | |
onCropComplete={onCropComplete} | |
onZoomChange={setZoom} | |
/> | |
</div> | |
</> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment