New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-image-cropper

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-image-cropper

react image crop

1.3.0
latest
Source
npm
Version published
Maintainers
1
Created
Source

React Image Cropper

Downloads Version

A React.JS Image Cropper Touch supported

See the demo

Custom:

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

Hot to Use

  • import {Cropper} from '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
ratiowidth / height
widthcropper frame width
heightcropper frame height
originXcropper original position(x axis), accroding to image left
originYcropper original position(Y axis), accroding 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
onImgLoadspecify fuction callback to run when the image completed loading
beforeImgloadspecify function callback to run when the image size value is ready but image is not completed loading
onChangetriggred when dragging stop, get values of cropper

See the demo

Keywords

react

FAQs

Package last updated on 30 Jan 2018

Did you know?

Socket

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