Coder Social home page Coder Social logo

malsapp / react-image-crop-component Goto Github PK

View Code? Open in Web Editor NEW

This project forked from exelban/react-image-crop-component

0.0 2.0 0.0 2.46 MB

Component for easy image cropping in react

Home Page: https://exelban.github.io/react-image-crop-component/

License: Apache License 2.0

JavaScript 92.26% CSS 7.74%

react-image-crop-component's Introduction

react-image-crop-component

Codacy grade David Travis Download Count

Demo image

Component for easy image cropping in react. Demo

Install

npm install react-image-crop-component

Usage

Include the main js module:

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

Include the main css:
If you use css compiler. I recommend browserify-css.

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

Or you can manualy add CSS.

Example

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

class Demo extends Component{
    constructor(){
        super();
        this.onCropped = this._onCropped.bind(this);
    }
    render(){
        return (<div style={{width: "300px", height: "300px"}}>
            <ReactImageCrop 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[0];
        let image_data = e[1];
    }
});

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

Props

Doubleclick on crop box will reset cropping.

src (REQUIRED, String)
<ReactImageCrop src="demo.jpg"/>

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

setWidth (optional, Number)
<ReactImageCrop setWidth={300} src="demo.jpg"/>

You can set cropper element width. Default 100%. (If you have some problems with size in Google Chrome, try to set his value).

setHeight (optional, Number)
<ReactImageCrop setHeight={300} src="demo.jpg"/>

You can set cropper element height. Default 100%. (If you have some problems with size in Google Chrome, try to set his value).

square (optional, Boolean)
<ReactImageCrop square={true} src="demo.jpg"/>

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

resize (optional, Boolean)
<ReactImageCrop resize={true} src="demo.jpg"/>

If true, user can resize cropping element. Default value is true

border (optional, String)
<ReactImageCrop border={"dashed #ffffff 2px"} src="demo.jpg"/>

You can set crop box border style.

onCrop (optional, Function)
<ReactImageCrop onCrop={this.test} src="demo.jpg"/>

A callback which happens after a resize, drag, or nudge. Passes the current crop state object, as well as a pixel-converted crop for your convenience. Return:

  [ 
    imageObject,
    {
        w: selection width,
        h: selection height,
        l: selection offsetLeft,
        t: selection offsetTop
    }
  ]

PropTypes

    src: PropTypes.string,
    setWidth: PropTypes.number,
    setHeight: PropTypes.number,
    square: PropTypes.bool,
    resize: PropTypes.bool,
    border: PropTypes.string,
    onCrop: PropTypes.func

License

Apache License 2.0

react-image-crop-component's People

Contributors

exelban avatar greenkeeper[bot] avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.