feat(cropper): expand image export API

This commit is contained in:
Maofeng
2026-09-29 17:46:16 +08:00
parent f56397fb97
commit 24b32ea5cc
13 changed files with 421 additions and 51 deletions
@@ -10,31 +10,25 @@ toc:
## 示例 {#example}
```tsx
import { Cropper, cropImage, type CropArea } from "@workspace/cropper"
import { Cropper, type CropperHandle } from "@workspace/cropper"
function AvatarCropper({ src }: { src: string }) {
const [area, setArea] = React.useState<CropArea>()
const cropperRef = React.useRef<CropperHandle>(null)
async function saveAvatar() {
if (!area) return
const blob = await cropImage(src, area, {
const blob = await cropperRef.current?.getCropImage({
height: 512,
shape: "circle",
type: "image/png",
width: 512,
})
await uploadAvatar(blob)
if (blob instanceof Blob) await uploadAvatar(blob)
}
return (
<div className="space-y-4">
<Cropper
src={src}
shape="circle"
className="size-72"
onCropAreaChange={setArea}
/>
<button type="button" disabled={!area} onClick={saveAvatar}>
<Cropper ref={cropperRef} src={src} shape="circle" className="size-72" />
<button type="button" onClick={saveAvatar}>
保存头像
</button>
</div>