1.3.6 • Published 5 years ago

@bearcanrun/react-image-cropper v1.3.6

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Forked from original React Image Cropper

Package no longer seemed to be maintained and required upgrading of package npm-run-all from critical security vulnerability. Also merged in LiHuang2's react16update branch. Upgraded to Webpack 4.

React Image Cropper

A React.JS Image Cropper Touch supported

See the demo

Custom:

  • initial cropper frame position
  • frame width, height, ratio
  • crop event

How to Use

  • import Cropper from '@bearcanrun/react-image-cropper'

  • styles are all inline

  • define Cropper with src, and ref to execute crop method

<Cropper
    src="http://braavos.me/images/posts/college-rock/the-smiths.png"
    ref={ ref => { this.cropper = ref }}
/>
  • crop and get image url

image.src = this.cropper.crop()

  • get crop values:

const values = this.cropper.values()

values:

{
    // display values
    display: {
        width, // frame width
        height, // frame height
        x, // original x position
        y, // original y position
        imgWidth, // img width
        imgHeight, // img height
    },
    // original values
    original: {
        width, // frame width
        height, // frame height
        x, // original x position
        y, // original y position
        imgWidth, // img width
        imgHeight, // img height
    }
}
  • onChange for preview

(values) => onChange(values)

  • custom use
propvalue
ratewidth / height
disabledboolean
widthcropper frame width
heightcropper frame height
originXcropper original position(x axis), according to image left
originYcropper original position(Y axis), according to image top
fixedRatioturn on/off fixed ratio (bool default true)
allowNewSelectionallow user to create a new selection instead of reusing initial selection (bool default true)
stylesspecify styles to override inline styles
imageLoadedspecify function callback to run when the image completed loading
beforeImageLoadedspecify function callback to run when the image size value is ready but the image has not completed loading
imageLoadErrorspecify function callback to run when the image errors during loading
onDragStopspecify function callback to run when dragging the crop has ended

See the demo