react-img-editor 是一个图像编辑器 react 组件,支持对图片进行裁剪、涂鸦、文字编辑、马赛克处理等操作,同时支持自定义插件和灵活的样式配置。

查看 demo
npm install react-img-editor -Simport ReactImgEditor from 'react-img-editor'
import 'react-img-editor/assets/index.css'
<ReactImgEditor src="https://www.w3schools.com/html/img_girl.jpg" />| 属性 | 描述 | 类型 | 默认值 | |
|---|---|---|---|---|
| src | 图片 url | string | - | |
| width | 画板宽度 | number? | 700 | |
| height | 画板高度 | number? | 500 | |
| style | 画板样式 | React.CSSProperties | - | |
| plugins | 自定义的插件 | Plugin[] | [] | |
| toolbar | 工具栏配置 | { items: string[] } | {items: ['pen', 'eraser', 'arrow', 'rect', 'circle', 'mosaic', 'text', ' | ', 'repeal', 'download', 'crop']} |
| getStage | 获取 KonvaJS 的 Stage 对象,可用于下载图片等操作 | (stage: any) => void | ||
| defaultPluginName | 默认选中的插件名称 | string? | - | |
| crossOrigin | 处理跨域图片 | string? | - | |
| pluginConfig | 插件配置项,可覆盖各插件的默认参数 | PluginConfig? | {} | |
| locale | 国际化语言设置,支持 'zh-CN' 和 'en' |
string? | 'zh-CN' |
开发
npm run starthttp://127.0.0.1:8012/examples/simple.html
发布
prepublishOnly 钩子会自动执行 guard 检查(lint)和构建,只需一条命令即可发布:
npm publish --otp=<你的6位验证码>验证码来自你绑定的身份验证器应用(如 Google Authenticator、Authy 等)。