1.1.2 • Published 6 years ago

react-image-crop-component v1.1.2

Weekly downloads
180
License
Apache-2.0
Repository
github
Last release
6 years ago

react-image-crop-component

Download Count

Demo image

Component for easy image cropping in react. Demo

Install

yarn add react-image-crop-component

Or with npm:

npm install react-image-crop-component --save

Usage

Include the main js module:

var ImageCrop = require('react-image-crop-component');
// or es6:
import ImageCrop from 'react-image-crop-component';

Include the styles:

require('react-image-crop-component/style.css');
// or es6:
import 'react-image-crop-component/style.css';

Example

import React, {Component} from 'react'
import {render} from 'react-dom'
import ImageCrop from 'react-image-crop-component'
import 'react-image-crop-component/style.css'

class Demo extends Component{
    constructor(){
        super()
        this.onCropped = this._onCropped.bind(this)
    }
    render(){
        return (<div style={{width: "300px", height: "300px"}}>
            <ImageCrop src="demo.jpg"
                            setWidth={300} 
                            setHeight={300} 
                            square={false} 
                            resize={true}
                            border={"dashed #ffffff 2px"}
                            onCrop={this.onCropped}/>
        </div>)
    },
    _onCropped: function (e) {
        let image = e.image
        let image_data = e.data
    }
});

render(<Demo/>, document.getElementById('app'));

Props

NameTypeDescription
srcstringMouse event with contains cursor position
maxWidthstringHTML node element
maxHeightstringHTML node element
squarebooleanHTML node element
watchFunctionCalled on crop
onCropFunctionCalled when crop action was finished
onResetFunctionCalled when crop box reset

src (REQUIRED, String)

<ImageCrop src="demo.jpg"/>

You can of course pass a blob path or base64 data.

maxWidth (optional, String)

<ImageCrop maxWidth='300px' src='demo.jpg'/>

Max width of crop component. Default script will try to set max width 100%. But if You have some problem with sizing, provide this value.

maxHeight (optional, String)

<ImageCrop maxHeight='300px' src='demo.jpg'/>

Max width of crop component. Default script will try to set max width 100%. But if You have some problem with sizing, provide this value.

square (optional, boolean)

<ImageCrop square={true} src='demo.jpg'/>

If true, the selection will have an a square one. Default value is false.

watch (optional, Function)

<ImageCrop watch={this.watch} src='demo.jpg'/>

A callback called continuously when user crop or drag cropping block. Return object:

{
  image: base64,
  data: {
    x number,
    y number,
    width number,
    height number,
  }
}

onCrop (optional, Function)

<ImageCrop onCrop={this.onCrop} src='demo.jpg'/>

A callback called when resize or drag event ended. Passes the current crop state object, as well as a pixel-converted crop for your convenience. Return the same object as in watch

onReset (optional, Function)

<ImageCrop onReset={this.onReset} src='demo.jpg'/>

This callback will be called when crop will be zero.

What's new

v1.1.2

- updated all dependencies;
- added flow types;
- added eslint;
- moved to Babel 7 for compiling;
- removed gulp;
- rewrite part of code;

License

Apache License 2.0

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago