项目作者: xfields

项目描述 :
An react component wrapping the Cropperjs.
高级语言: JavaScript
项目地址: git://github.com/xfields/rc-cropper.git
创建时间: 2017-07-17T12:14:23Z
项目社区:https://github.com/xfields/rc-cropper

开源协议:MIT License

下载


rc-cropper

An react component wrapping the Cropperjs.

Cropperjs Docs

Installation

Install via npm

  1. npm install --save rc-cropper

Example

Inspired by react-cropper

  1. import React, {Component} from 'react'
  2. import Cropper from 'rc-cropper'
  3. class Demo extends Component {
  4. crop(){
  5. const canvas = this.refs.cropper.getCroppedCanvas()
  6. const url = canvas.toDataURL() // image url
  7. const blob = canvas.toBlob(blob => {
  8. // upload the blob or do anything else
  9. })
  10. }
  11. render() {
  12. const options = {
  13. aspectRatio: 16 / 9
  14. }
  15. return (
  16. <Cropper
  17. ref='cropper'
  18. src='http://fengyuanchen.github.io/cropper/images/picture.jpg'
  19. options={options} ></Cropper>
  20. )
  21. }
  22. }

Props

name type default description
src string image src
className string custom class name
locale object for i18n
zoomStep number 0.2 zoom step
moveStep number 2px move step
rotateStep number 45deg rotate step
onReady function callback when the cropper is ready
showActions bool false whether show action buttons, support zoom/move/rotate
outputImgSize object specify the output canvas size, format: {width: , height: }
containerSizeLimit object { maxWidth: 500, maxHeight: 500, minWidth: 50, minHeight: 50} the size limitation of image container
cropBoxEditable bool true Whether the cropbox width and height can edit by input. If outputImgSize is set, this property would be invaild
shouldRender bool true should initiate the cropper instance, the cropper instance will be intiated when shouldRender become true and the image is loaded.
options object options for cropperjs

Note:

  • If outputImgSize is specified and no aspectRatio specified in options, rc-cropper will caculate the aspectRatio based on outputImgSize automatically. aspectRation = outputImgSize.width / outputImgSize.height