# dbb-img-crop

> 一个react的弹框式图片裁剪插件,支持预览，旋转

Latest version **1.2.1** (published 2020-09-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install dbb-img-crop
pnpm add dbb-img-crop
yarn add dbb-img-crop
bun add dbb-img-crop
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2020-09-03 |
| First published | 2020-08-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 543.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | dengbinbin |
| Maintainers | dengbinbin |
| Keywords | react, reactjs, image, crop, react-component |

## Links

- npm: https://www.npmjs.com/package/dbb-img-crop
- Repository: https://github.com/dbb1016606796/dbb-img-crop
- Homepage: https://github.com/dbb1016606796/dbb-img-crop#readme
- Issues: https://github.com/dbb1016606796/dbb-img-crop/issues
- npm.io page: https://npm.io/package/dbb-img-crop

## Dependencies (5)

- [clsx](https://npm.io/package/clsx.md) ^1.0.4
- [core-js](https://npm.io/package/core-js.md) ^3.4.2
- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.11.2
- [react-image-crop](https://npm.io/package/react-image-crop.md) ^8.6.5

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.2.1 (latest) — 2020-09-03
- 1.2.0 — 2020-09-03
- 1.1.3 — 2020-09-02
- 1.1.2 — 2020-09-02
- 1.1.1 — 2020-09-02
- 1.1.0 — 2020-09-02
- 1.0.3 — 2020-09-01
- 1.0.2 — 2020-09-01
- 1.0.1 — 2020-08-31
- 1.0.0 — 2020-08-31

## README

###### 一款基于[react-image-crop](https://github.com/DominicTobias/react-image-crop)二次开发的，图片裁剪工具

```javascript
npm install dbb-img-crop --save
```

######  node>=10.13.0

######  效果预览
<div>
<p>裁剪demo</p>
<img src="http://yjw-image.oss-cn-shenzhen.aliyuncs.com/npm/demo1.gif" />
<p>裁剪+水印</p>
<img src="http://yjw-image.oss-cn-shenzhen.aliyuncs.com/npm/demo2.gif" />
</div>

###### 使用示例

```javascript
import React, { Component } from 'react';
import ReactDOM from 'react-dom'; 
import ReactCrop from 'dbb-img-crop';

const blockSize = {
  width: 460,
  height: 590,
};
const cropSize = {
  width: 800,
  height: 600,
};

class App extends Component {
  state = {
    src: null,
  };

  onSelectFile = e => {
    if (e.target.files && e.target.files.length > 0) {
      this.setState({ src: e.target.files[0] });
    }
  };

	handleSubmit = ({file,event}) => {
    // 会返回一个对象,file参数就是一个Blob对象
   // 如果你使用antd的插件，传进来的File对象有name和uid字段,返回的Blob对象都会有这两个key-	value 
   //如果还需要回显，可以 img.src = new Blob(file)     
    conosle.log(file);  
  	};

  render() {
    const { src } = this.state;

    return (
      <div className="App">
        <h1>下面将开始测试</h1>
        <div>
          <input type="file" onInput={this.onSelectFile} />
        </div>
        {src && (
          <>
            <ReactCrop
              //locked={true}  true == 裁剪框不可以自定义尺寸
              //ruleOfThirds={true} true == 开启裁剪框九宫格
              file={src}
              handleSubmit={blob => {
                //设置照片回显
                const src = URL.createObjectURL(blob.file),
                  img = document.createElement('img');
                img.src = src;
                img.style.margin = '0 auto';
                img.style.display = 'block';
                document.body.appendChild(img);
                this.setState({ src: null });
              }}
              close={() => this.setState({ src: null })}
            />
          </>
        )}
      </div>
    );
  }
}
```

| 参数名字                                   | 参数说明                                                    |
| ------------------------------------------ | ----------------------------------------------------------- |
| file                                       | 图片的File对象(必传)                                        |
| handleSubmit                               | 点击确定之后的回调函数:({file:Blob,event}) => {}            |
| close                                      | 关闭整个弹出层的回调函数                                    |
| title                                      | 弹出尘的标题，default：编辑图片                             |
| blockSize：{width：number, height：number} | 裁剪框的尺寸，默认尺寸：width：222，height：296             |
| cropSize：object<style>                    | 裁剪之后的照片回显样式，默认回显照: width：111，hegiht：148 |
| rotate：boolean                            | 是否开启旋转，default：false                                |
| wrapStyle：object<style>                   | 最外层容器的样式                                            |
| leftStyle：object<style>                   | 左边容器的样式                                              |
| scrollBar：boolean                         | 是否显示滚动条，default：false                              |
| watermark：boolean                         | 是否开启添加水印功能，defalut：false                        |
| watermarkStyle：object<style>              | 添加水印的操作的样式                                        |
| maxWatermarkSize：[width,height]           | 设置水印的最大宽高,不传则不限制                             |
| defaultWatermarkSize：[width,height]       | 设置水印的默认尺寸，defalut：[50,50]                        |
| accept：string                             | 水印图片的类型，default："image/png, image/jpeg"            |

[^{...props}]: 支持所有react-image-crop的参数



##### 更新日志

###### 1.2.1

1. md说明的冲突忘记解决了，解决下。

###### 1.2.0

1. 新增添加水印功能。

###### 1.1.1

1. 新增wrapStyle属性。
2. 新增leftStyle属性。
3. 新增git图演示

###### 1.1.0

1. 新增旋转功能
2. 布局方式变动，如果裁剪框+预览 不大于当前屏幕宽度的80%，将会水平剧中对齐显示
3. css文件最终将会打包进js文件，不再单独打包成js和css文件

###### 1.0.3

1. 裁剪框添加了阴影。
2. button按钮添加了一个类型 *type*="button"
3. handleSubmit传递参数新增 event

---
_Source: https://npm.io/package/dbb-img-crop · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
