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

mm-react-cropperjs

v1.3.1

Published

React wrapper around the CropperJS library

Downloads

3

Readme

DDM React CropperJS

CropperJS wrapped in a React component

See the CropperJS Documentation for more information

Inspiration taken from react-cropper

Installation

npm install --save ddm-react-cropperjs

NOTE: You must include the cropper.css (or cropper.min.css) file in your project. It can be found in node_modules/cropperjs/dist.

Example

See example/example.jsx

Props

src

The image source URL.

  • Required
  • Type: string
  • Default: null

alt

The text for the image alt attribute.

  • Type: string
  • Default: picture

aspectRatio

Set the aspect ratio of the crop box. By default, the crop box is free ratio.

  • Type: number
  • Default: N/A

https://github.com/fengyuanchen/cropperjs#aspectratio

canvasData

Change the canvas (image wrapper) position and size with new data.

  • Type: object
  • Default: null
canvasData = {
  left: 200,
  top: 200,
  width: 600,
  height: 400
}

https://github.com/fengyuanchen/cropperjs#setcanvasdatadata

crop

This event fires when the canvas (image wrapper) or the crop box changed.

  • Type: function
  • Default: N/A

Parameters

  • event: Custom event object
  • dataURL: The cropped image data URL returned in the format specified in the imgType prop
<ReactCropperJS
  crop={(event, dataURL)} => {
    console.log(event.detail);
    this.img.src = dataURL;
  }}
/>

https://github.com/fengyuanchen/cropperjs#crop-2

cropBoxData

Change the crop box position and size with new data.

  • Type: object
  • Default: null
cropBoxData = {
  left: 200,
  top: 200,
  width: 600,
  height: 400
}

https://github.com/fengyuanchen/cropperjs#setcropboxdatadata

cropend

This event fires when the canvas (image wrapper) or the crop box stops changing.

  • Type: function
  • Default: N/A

Parameters

  • event: Custom event object
  • dataURL: The cropped image data URL returned in the format specified in the imgType prop
<ReactCropperJS
  cropend={(event, dataURL)} => {
    console.log(event.detail);
    this.img.src = dataURL;
  }}
/>

https://github.com/fengyuanchen/cropperjs#cropend-1

cropmove

This event fires when the canvas (image wrapper) or the crop box is changing.

  • Type: function
  • Default: N/A

Parameters

  • event: Custom event object
  • dataURL: The cropped image data URL returned in the format specified in the imgType prop
<ReactCropperJS
  cropmove={(event, dataURL)} => {
    console.log(event.detail);
    this.img.src = dataURL;
  }}
/>

https://github.com/fengyuanchen/cropperjs#cropmove-1

cropstart

This event fires when the canvas (image wrapper) or the crop box starts to change.

  • Type: function
  • Default: N/A

Parameters

  • event: Custom event object
  • dataURL: The cropped image data URL returned in the format specified in the imgType prop
<ReactCropperJS
  cropstart={(event, dataURL)} => {
    console.log(event.detail);
    this.img.src = dataURL;
  }}
/>

https://github.com/fengyuanchen/cropperjs#cropstart-1

crossOrigin

The value to set crossOrigin attribute to on the img element. Related to the checkCrossOrigin option.

  • Type: string
  • Default: null

More info on the crossOrigin attribute: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-crossorigin

data

Change the cropped area position and size with new data (based on the original image).

  • Type: object
  • Default: null

https://github.com/fengyuanchen/cropperjs#setdatadata

dragMode

Change the drag mode.

  • Type: string
  • Default: crop
  • Options: none, crop, move

https://github.com/fengyuanchen/cropperjs#dragmode

enable

Boolean flag to enable or disable the component. Setting the value to false will disable it.

  • Type: bool
  • Default: true

https://github.com/fengyuanchen/cropperjs#enable

https://github.com/fengyuanchen/cropperjs#disable

imgType

The image type to return when getting the cropped image data URL from the canvas using toDataURL. Valid options are image/png, image/jpeg, and image/webp. If the data URL returned shows that the format is PNG, then that means the image type submitted is not supported.

  • Type: string
  • Default: image/jpeg

For more information see the type parameter here:

https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL

imgQuality

The quality of the image to return when getting the cropped image data URL from the canvas using toDataURL. Should be a value between 0 and 1 (a percentage). If the value is anything else, the default value of 0.92 will be used.

  • Type: number
  • Default: 0.92

For more information see the encoderOptions parameter here:

https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL

moveTo

Move the canvas (image wrapper) to an absolute point.

  • Type: array
  • Default: N/A
moveTo = [
  100, // X value
  200  // Y value
]

https://github.com/fengyuanchen/cropperjs#movetox-y

ready

This event fires when the target image has been loaded and the cropper instance is ready for cropping.

  • Type: function
  • Default: N/A

https://github.com/fengyuanchen/cropperjs#ready-1

rotateTo

Rotate the image to an absolute degree.

  • Type: number
  • Default: 0

https://github.com/fengyuanchen/cropperjs#rotatetodegree

scaleX

Scale the abscissa of the image.

  • Type: number
  • Default: 1

https://github.com/fengyuanchen/cropperjs#scalexscalex

scaleY

Scale the ordinate of the image.

  • Type: number
  • Default: 1

https://github.com/fengyuanchen/cropperjs#scaleyscaley

style

Custom styles for the component placed on the wrapping element of the component.

  • Type: object
  • Default: null

zoom

This event fires when a cropper instance starts to zoom in or zoom out its canvas (image wrapper).

  • Type: function
  • Default: N/A

Parameters

  • event: Custom event object
  • dataURL: The cropped image data URL returned in the format specified in the imgType prop
<ReactCropperJS
  zoom={(event, dataURL)} => {
    console.log(event.detail);
    this.img.src = dataURL;
  }}
/>

https://github.com/fengyuanchen/cropperjs#zoom-1

zoomTo

Zoom the canvas (image wrapper) to an absolute ratio.

  • Type: number
  • Default: 1

https://github.com/fengyuanchen/cropperjs#zoomtoratio

Other props

Accepts all options found in the CropperJS documentation as props. Except for the props listed above, all props passed in are set only when the component is mounted and cannot be changed unless the component is unmounted and re-mounted.

License

MIT