npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-image-crop-component

v1.1.2

Published

Component for easy image cropping in react

Downloads

733

Readme

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

Name | Type | Description --- | --- | --- src | string | Mouse event with contains cursor position maxWidth | string | HTML node element maxHeight | string | HTML node element square | boolean | HTML node element watch | Function | Called on crop onCrop | Function | Called when crop action was finished onReset | Function | Called 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