Skip to content

Commit

Permalink
Add crop ratio prop
Browse files Browse the repository at this point in the history
  • Loading branch information
bearcanrun committed Oct 4, 2018
1 parent 39d2ef4 commit 62eff90
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/image-upload/components/CropperDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CropperDialog extends Component {
}

render () {
const { classes, open, handleClose, imgSrc, handleCrop, handleCancel, cropperRef } = this.props
const { classes, open, handleClose, imgSrc, handleCancel, cropperRef, cropRatio } = this.props
console.log(cropperRef)
return (
<Dialog
Expand All @@ -49,7 +49,7 @@ class CropperDialog extends Component {
originX={100}
originY={100}
ref={this.cropper}
ratio={1}
ratio={cropRatio}
/>
)}
</div>
Expand All @@ -71,7 +71,6 @@ class CropperDialog extends Component {
}

async handleCrop () {
console.log('CropperDialog handleCrop: ', this.cropper.current)
const cropped = this.cropper.current.crop()
this.props.handleCrop(cropped)
}
Expand All @@ -84,7 +83,8 @@ CropperDialog.propTypes = {
imgSrc: PropTypes.string,
handleCrop: PropTypes.func.isRequired,
cropperRef: PropTypes.any.isRequired,
handleCancel: PropTypes.func.isRequired
handleCancel: PropTypes.func.isRequired,
cropRatio: PropTypes.number.isRequired
}

export default withStyles(styles)(CropperDialog)
9 changes: 6 additions & 3 deletions src/image-upload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const cropConfigDefault = {
x: 10,
y: 10,
width: 200,
height: 200
height: 200,
ratio: 1 / 1
}

// default config for image resize and quality
Expand Down Expand Up @@ -78,7 +79,8 @@ class ImageUpload extends Component {
render () {
const {
classes,
existingImage
existingImage,
cropRatio
} = this.props

let image = null
Expand Down Expand Up @@ -114,6 +116,7 @@ class ImageUpload extends Component {
handleCancel={this.handleCancel}
cropImagePreview={this.cropPreview}
cropperRef={this.cropper}
cropRatio={cropRatio}
/>
</React.Fragment>
)}
Expand Down Expand Up @@ -145,7 +148,6 @@ class ImageUpload extends Component {
}

async handleCrop (cropped) {
console.log('handleCrop', this.cropped)
const croppedBlob = await imgSrcToBlob(cropped, 'image/png', 'Anonymous')
let resizedBlob = await readAndCompressImage(croppedBlob, this.saveConfig)

Expand Down Expand Up @@ -197,6 +199,7 @@ ImageUpload.propTypes = {
classes: PropTypes.object.isRequired,
cropContainerConfig: PropTypes.object, // { x: 10, y: 10, width: 200, height: 200 } (default)
cropPreviewBox: PropTypes.object, // { width: 350, height: 350 } (default)
cropRatio: PropTypes.number.isRequired, // ratio (width/height) image is cropped at eg. 1/1, 4/1, 16/9, 800/150
saveImageConfig: PropTypes.object, // see imageResizeConfig above for default (default)
containerName: PropTypes.string.isRequired, // name of Azure Container image will be saved in
fileName: PropTypes.string.isRequired, // filename to save image as
Expand Down

0 comments on commit 62eff90

Please sign in to comment.