Socket
Socket
Sign inDemoInstall

react-cropper

Package Overview
Dependencies
6
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-cropper

Cropper as React components


Version published
Weekly downloads
130K
decreased by-15.57%
Maintainers
1
Install size
3.74 MB
Created
Weekly downloads
 

Readme

Source

react-cropper

Cropper as React components

NPM

Demo

Docs

Installation

Before you install react-cropper please make sure npm install jquery --save first or it will install another jquery depedency deep in react-cropper/node_modules/cropper/node_modules/jquery

Install via npm

npm install --save react-cropper

Webpack User

You also need a couple of loaders for webpack

npm install style-loader css-loader

Browserify User

https://github.com/cheton/browserify-css

npm i --save-dev browserify-css

Compile your project with command line like

 browserify -t reactify -g browserify-css index.jsx > bundle.js

If you are using gulp, browserify or other build tools, make sure you enable global option true

For example in gulp you should do

b.transform(browserifycss, {global: true});

Todo

Quick Example

var Cropper = require('react-cropper');
var Demo = React.createClass({
  _crop: function(){
    // image in dataUrl
    console.log(this.refs.cropper.getCroppedCanvas().toDataURL());
  },

  render: function() {
    return (
      <Cropper
        ref='cropper'
        src='http://fengyuanchen.github.io/cropper/img/picture.jpg'
        style={{height: 400, width: '100%'}}
        // Cropper.js options
        aspectRatio={16 / 9}
        guides={false}
        crop={this._crop} />
    );
  }
});

Options

src

  • Type: string
  • Default: null
  <Cropper src='http://fengyuanchen.github.io/cropper/img/picture.jpg' />

Other options

Accept all options in the docs as attributes.

  <Cropper
    src='http://fengyuanchen.github.io/cropper/img/picture.jpg'
    aspectRatio={16 / 9} 
    guides={false} 
    crop={this._crop} />

Methods

Assign a ref attribute to use methods

var Demo = React.createClass({

  _crop: function(){
    var dataUrl = this.refs.cropper.getCroppedCanvas().toDataURL();
    console.log(dataUrl);
  },

  render: function() {
    return (
      <Cropper
        ref='cropper'
        crop={this._crop} />
    );
  }
})

Events

Assign Events handler with .on(eventname, callback) and ref.


componentDidMount: function(){
  this.refs.cropper.on('dragstart.cropper', function (e) {
    console.log(e.type); // dragstart
    console.log(e.namespace); // cropper
    console.log(e.dragType); // ...
  });
},

Build

npm run build

Author

Fong Kuanghuei(waneblade@gmail.com)

License

MIT

Keywords

FAQs

Last updated on 10 Sep 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc