npm install cropic
bath
$ npm install cropic
`
在 vue 项目里使用
`html
// xxx.vue
`
在 react 项目里使用
`tsx
import React, { useState } from 'react'
import Cropic from 'cropic'
export default () => {
const [src, setSrc] = useState('')
const cropBtn = (event) => {
const cropic = new Cropic()
const files = event?.target.files
const reader = new FileReader()
reader.readAsDataURL(files[0])
reader.onload = (img) => {
cropic.getImage({
// width: 500,
// height: 500,
src: img?.target?.result,
name: 'cropic',
encode: 'base64', // 支持 base64、blob、file
type: 'png',
// quality: '0.9', // 导出图片的质量
// buttonText: ['Cancel', 'Reset', 'Done'],
// buttonColor: ['#fff', '#3680fd', '#23c667'],
// buttonSize: 12,
onDone: (base64) => {
setSrc(base64)
},
onCancel: function () {
console.log('取消裁剪')
}
})
}
}
return (
src={src}
style={{ width: '100px', height: '100px', borderRadius: '50%' }}
/>
)
}
`
cdn 方式
`html
``