Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mununki/simple-react-cropper
Simple React image cropper with cropper.js
https://github.com/mununki/simple-react-cropper
cropperjs react typescript
Last synced: about 2 months ago
JSON representation
Simple React image cropper with cropper.js
- Host: GitHub
- URL: https://github.com/mununki/simple-react-cropper
- Owner: mununki
- License: mit
- Created: 2019-01-16T13:26:31.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-10T22:28:39.000Z (about 2 years ago)
- Last Synced: 2024-04-24T22:10:03.789Z (8 months ago)
- Topics: cropperjs, react, typescript
- Language: TypeScript
- Size: 1.68 MB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple-React-Cropper
### [Demo](https://mattdamon108.github.io/simple-react-cropper/)
[![npm version](https://badge.fury.io/js/simple-react-cropper.svg)](https://badge.fury.io/js/simple-react-cropper)
This is the tiny and simple image cropper & resizer based on [Cropper.js](https://fengyuanchen.github.io/cropperjs/). Simply it is wrapped to React Component to allow to use more easily in React project.
There are many functions of Cropper.js but this module is simplified with main features in purpose of avatar image crop & resize in most user-profile web page.
### Features
1. Crop and Resize the images in Web canvas (powered by [Cropper.js](https://fengyuanchen.github.io/cropperjs/)).
2. Handle the cropped and resized images with function props.
3. Style the container of crop canvas.
4. **Typescript support**### Install
```shell
$ npm i simple-react-cropper# or
$ yarn add simple-react-cropper
```### Example
```javascript
import React from "react";
import ReactDOM from "react-dom";
import Cropper from "simple-react-cropper";const uploadToServer = blob => {
console.log(blob);
};const afterCrop = () => {
console.log("close cropper");
};const Root = () => (
);ReactDOM.render(, document.getElementById("root"));
```
### Props
| Props | Type | required | Default | Descriptioin |
| -------------- | ------------------- | -------- | --------- | ------------------------------------------------------------------------ |
| aspectRatio | number | true | NaN | Define the fixed crop box ratio. By default, the crop box has free ratio |
| width | number | false | 500 | The width of output image |
| height | number | false | 500 | The height of output image |
| upload | function | true | undefined | The function to handle the output (blob type) |
| afterCrop | function | false | undefined | The function to be called after confirming cropping |
| fillColor | string | false | "#FFF" | The color to be filled in blank area after crop |
| containerStyle | React.CSSProperties | false | undefined | The object to style the parent container |